walkor 2 gadi atpakaļ
vecāks
revīzija
69fea2bc8d
2 mainītis faili ar 12 papildinājumiem un 10 dzēšanām
  1. 7 5
      src/Events/Swow.php
  2. 5 5
      src/Worker.php

+ 7 - 5
src/Events/Swow.php

@@ -65,13 +65,14 @@ class Swow implements EventInterface
     {
         $t = (int) ($delay * 1000);
         $t = max($t, 1);
-        $coroutine = Coroutine::run(function () use ($t, $func, $args): void {
+        $that = $this;
+        $coroutine = Coroutine::run(function () use ($t, $func, $args, $that): void {
             msleep($t);
             unset($this->eventTimer[Coroutine::getCurrent()->getId()]);
             try {
                 $func(...(array) $args);
             } catch (\Throwable $e) {
-                $this->error($e);
+                $that->error($e);
             }
         });
         $timerId = $coroutine->getId();
@@ -86,13 +87,14 @@ class Swow implements EventInterface
     {
         $t = (int) ($interval * 1000);
         $t = max($t, 1);
-        $coroutine = Coroutine::run(static function () use ($t, $func, $args): void {
+        $that = $this;
+        $coroutine = Coroutine::run(static function () use ($t, $func, $args, $that): void {
             while (true) {
                 msleep($t);
                 try {
                     $func(...(array) $args);
                 } catch (\Throwable $e) {
-                    $this->error($e);
+                    $that->error($e);
                 }
             }
         });
@@ -268,7 +270,7 @@ class Swow implements EventInterface
      */
     public function stop()
     {
-        Coroutine::getMain()->kill();
+        Coroutine::killAll();
     }
 
     /**

+ 5 - 5
src/Worker.php

@@ -1526,12 +1526,12 @@ class Worker
             $worker->setUserAndGroup();
             $worker->id = $id;
             $worker->run();
-            if (strpos(static::$eventLoopClass, 'Workerman\Events\Swoole') !== false) {
-                exit(0);
+            if (static::$status !== self::STATUS_SHUTDOWN) {
+                $err = new Exception('event-loop exited');
+                static::log($err);
+                exit(250);
             }
-            $err = new Exception('event-loop exited');
-            static::log($err);
-            exit(250);
+            exit(0);
         } else {
             throw new Exception("forkOneWorker fail");
         }