walkor 2 years ago
parent
commit
58e0cff89e

+ 2 - 2
src/Events/Ev.php

@@ -59,7 +59,7 @@ class Ev implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function delay(float $delay, $func, $args)
+    public function delay(float $delay, $func, $args = [])
     {
         $timerId = self::$timerId;
         $event = new \EvTimer($delay, 0, function () use ($func, $args, $timerId) {
@@ -94,7 +94,7 @@ class Ev implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function repeat(float $interval, $func, $args)
+    public function repeat(float $interval, $func, $args = [])
     {
         $event = new \EvTimer($interval, $interval, function () use ($func, $args) {
             $func(...(array)$args);

+ 2 - 2
src/Events/Event.php

@@ -87,7 +87,7 @@ class Event implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function delay(float $delay, $func, $args)
+    public function delay(float $delay, $func, $args = [])
     {
         $className = $this->eventClassName;
         $timerId = $this->timerId++;
@@ -130,7 +130,7 @@ class Event implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function repeat(float $interval, $func, $args)
+    public function repeat(float $interval, $func, $args = [])
     {
         $className = $this->eventClassName;
         $timerId = $this->timerId++;

+ 2 - 2
src/Events/EventInterface.php

@@ -22,7 +22,7 @@ interface EventInterface
      * @param $args
      * @return int|bool
      */
-    public function delay(float $delay, $func, $args);
+    public function delay(float $delay, $func, $args = []);
 
     /**
      * Repeatedly execute a callback.
@@ -31,7 +31,7 @@ interface EventInterface
      * @param $args
      * @return int|bool
      */
-    public function repeat(float $interval, $func, $args);
+    public function repeat(float $interval, $func, $args = []);
 
     /**
      * Delete a delay timer.

+ 2 - 2
src/Events/Revolt.php

@@ -98,7 +98,7 @@ class Revolt implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function delay(float $delay, $func, $args)
+    public function delay(float $delay, $func, $args = [])
     {
         $args = (array)$args;
         $timerId = $this->timerId++;
@@ -114,7 +114,7 @@ class Revolt implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function repeat(float $interval, $func, $args)
+    public function repeat(float $interval, $func, $args = [])
     {
         $args = (array)$args;
         $timerId = $this->timerId++;

+ 10 - 3
src/Events/Select.php

@@ -23,6 +23,12 @@ use Workerman\Worker;
 class Select implements EventInterface
 {
     /**
+     * Running.
+     * @var bool
+     */
+    protected $running = true;
+
+    /**
      * All listeners for read/write event.
      *
      * @var array
@@ -112,7 +118,7 @@ class Select implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function delay(float $delay, $func, $args)
+    public function delay(float $delay, $func, $args = [])
     {
         $timerId = $this->timerId++;
         $runTime = \microtime(true) + $delay;
@@ -129,7 +135,7 @@ class Select implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function repeat(float $delay, $func, $args)
+    public function repeat(float $delay, $func, $args = [])
     {
         $timerId = $this->timerId++;
         $runTime = \microtime(true) + $delay;
@@ -329,7 +335,7 @@ class Select implements EventInterface
      */
     public function run()
     {
-        while (1) {
+        while ($this->running) {
             if (\DIRECTORY_SEPARATOR === '/') {
                 // Calls signal handlers for pending signals
                 \pcntl_signal_dispatch();
@@ -382,6 +388,7 @@ class Select implements EventInterface
      */
     public function stop()
     {
+        $this->running = false;
         $this->deleteAllTimer();
         foreach ($this->signalEvents as $signal => $item) {
             $this->offsignal($signal);

+ 2 - 2
src/Events/Swoole.php

@@ -46,7 +46,7 @@ class Swoole implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function delay(float $delay, $func, $args)
+    public function delay(float $delay, $func, $args = [])
     {
         $t = (int)($delay * 1000);
         $t = $t < 1 ? 1 : $t;
@@ -86,7 +86,7 @@ class Swoole implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function repeat(float $interval, $func, $args)
+    public function repeat(float $interval, $func, $args = [])
     {
         if ($this->mapId > \PHP_INT_MAX) {
             $this->mapId = 0;

+ 2 - 2
src/Events/Swow.php

@@ -56,7 +56,7 @@ class Swow implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function delay(float $delay, $func, $args)
+    public function delay(float $delay, $func, $args = [])
     {
         $t = (int) ($delay * 1000);
         $t = max($t, 1);
@@ -77,7 +77,7 @@ class Swow implements EventInterface
     /**
      * {@inheritdoc}
      */
-    public function repeat(float $interval, $func, $args)
+    public function repeat(float $interval, $func, $args = [])
     {
         $t = (int) ($interval * 1000);
         $t = max($t, 1);

+ 1 - 2
src/Timer.php

@@ -218,8 +218,7 @@ class Timer
         if (self::$event) {
             return self::$event->offDelay($timerId);
         }
-        foreach(self::$tasks as $runTime => $taskData) 
-        {
+        foreach(self::$tasks as $runTime => $taskData) {
             if(array_key_exists($timerId, $taskData)) {
                 unset(self::$tasks[$runTime][$timerId]);
             }