walkor 2 years ago
parent
commit
1a62c4e760
3 changed files with 14 additions and 1 deletions
  1. 1 1
      src/Events/Revolt.php
  2. 9 0
      src/Events/Swoole.php
  3. 4 0
      src/Events/Swow.php

+ 1 - 1
src/Events/Revolt.php

@@ -118,7 +118,7 @@ class Revolt implements EventInterface
     {
         $args = (array)$args;
         $timerId = $this->timerId++;
-        $closure = function () use ($func, $args, $timerId) {
+        $closure = function () use ($func, $args) {
             $func(...$args);
         };
         $cbId = $this->driver->repeat($interval, $closure);

+ 9 - 0
src/Events/Swoole.php

@@ -49,6 +49,15 @@ class Swoole implements EventInterface
     protected $errorHandler;
 
     /**
+     * Construct
+     */
+    public function __construct()
+    {
+        // Avoid process exit due to no listening
+        Timer::tick(100000000, function () {});
+    }
+
+    /**
      * {@inheritdoc}
      */
     public function delay(float $delay, $func, $args = [])

+ 4 - 0
src/Events/Swow.php

@@ -148,6 +148,10 @@ class Swow implements EventInterface
             try {
                 $this->readEvents[$fd] = Coroutine::getCurrent();
                 while (true) {
+                    if (!\is_resource($stream)) {
+                        $this->offReadable($stream);
+                        break;
+                    }
                     $rEvent = stream_poll_one($stream, STREAM_POLLIN | STREAM_POLLHUP);
                     if (!isset($this->readEvents[$fd]) || $this->readEvents[$fd] !== Coroutine::getCurrent()) {
                         break;