Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Nov 5, 2024
1 parent 392dc06 commit 2fe3ce7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,17 @@ class Worker

/**
* Is worker stopping ?
*
* @var bool
*/
public bool $stopping = false;

/**
* EventLoop class.
*
* @var class-string<EventInterface>
* @var ?string
*/
public string $eventLoop;
public ?string $eventLoop = null;

/**
* Daemonize.
Expand Down Expand Up @@ -750,7 +752,7 @@ protected static function initWorkers(): void
$worker->context->statusSocket = $worker->getSocketName();

// Event-loop name.
$eventLoopName = $worker->eventLoop ?? static::$eventLoopClass;
$eventLoopName = $worker->eventLoop ?: static::$eventLoopClass;
$worker->context->eventLoopName = str_starts_with($eventLoopName, 'Workerman\\Events\\') ? strtolower(substr($eventLoopName, 17)) : $eventLoopName;

// Status name.
Expand Down Expand Up @@ -1434,7 +1436,7 @@ protected static function forkWorkersForWindows(): void

// Create a global event loop.
if (static::$globalEvent === null) {
$eventLoopClass = $worker->eventLoop ?? static::$eventLoopClass;
$eventLoopClass = $worker->eventLoop ?: static::$eventLoopClass;
static::$globalEvent = new $eventLoopClass();
static::$globalEvent->setErrorHandler(function ($exception) {
static::stopAll(250, $exception);
Expand Down Expand Up @@ -1574,7 +1576,7 @@ protected static function forkOneWorkerForLinux(self $worker): void

// Create a global event loop.
if (static::$globalEvent === null) {
$eventLoopClass = $worker->eventLoop ?? static::$eventLoopClass;
$eventLoopClass = $worker->eventLoop ?: static::$eventLoopClass;
static::$globalEvent = new $eventLoopClass();
static::$globalEvent->setErrorHandler(function ($exception) {
static::stopAll(250, $exception);
Expand Down

0 comments on commit 2fe3ce7

Please sign in to comment.