From 9a3e1d8e6fb4e1981a12db1396bb6f3d7ea79804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 14 Apr 2021 11:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Crontab/Crontab.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/System/Crontab/Crontab.php b/System/Crontab/Crontab.php index 0f9c24e9..599c2827 100644 --- a/System/Crontab/Crontab.php +++ b/System/Crontab/Crontab.php @@ -45,6 +45,18 @@ class Crontab extends BaseObject private array|Closure|null $_max_execute_handler = null; + private bool $_stop = false; + + + /** + * + */ + public function stop() + { + $this->_stop = true; + } + + /** * @return $this */ @@ -116,6 +128,9 @@ class Crontab extends BaseObject */ public function setHandler(array|Closure $handler): void { + if ($handler instanceof Closure) { + Closure::bind($handler, $this, $this); + } $this->handler = $handler; } @@ -255,6 +270,9 @@ class Crontab extends BaseObject */ private function after(): void { + if ($this->_stop === true) { + return; + } if ($this->isLoop()) { $this->recover(); return;