这里写问题描述
public function run(): void
{
$this->listen();
if (!$this->onWorkerStart) {
return;
}
// Try to emit onWorkerStart callback.
$callback = function() {
try {
($this->onWorkerStart)($this);
} catch (Throwable $e) {
// Avoid rapid infinite loop exit.
sleep(1);
static::stopAll(250, $e);
}
};
switch (Worker::$eventLoopClass) {
case Swoole::class:
case Swow::class:
case Fiber::class:
Coroutine::create($callback);
break;
default:
(new \Fiber($callback))->start();
}
}
onMessage,onConnect,onClose等协程创建是在
Events/Swoole.php
Events/Swow.php
Events/Fiber.php
中完成的。onWorkerStart不归Events管,所以单独手动创建了一个协程去执行。
感谢作者大佬