From c99afea2a9154b6609abf6cd02bcc95ebb266a15 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 22 Nov 2023 22:58:40 -0500 Subject: [PATCH 1/2] Kill any running tasks when force closed --- src/Fork.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Fork.php b/src/Fork.php index 5aef9f5..5647412 100644 --- a/src/Fork.php +++ b/src/Fork.php @@ -157,11 +157,15 @@ protected function listenForSignals(): void protected function exit(): void { - if (extension_loaded('posix')) { - posix_kill(getmypid(), SIGKILL); + if (! extension_loaded('posix')) { + exit; } - exit; + foreach ($this->runningTasks as $task) { + posix_kill($task->pid(), SIGKILL); + } + + posix_kill(getmypid(), SIGKILL); } protected function currentlyInChildTask(int $pid): bool From 3e4c67a7fbaec7bf843cf8e338d07b60c8bc2100 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 22 Nov 2023 23:03:58 -0500 Subject: [PATCH 2/2] Remove space --- tests/ForkTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ForkTest.php b/tests/ForkTest.php index 94eb919..9222b7d 100644 --- a/tests/ForkTest.php +++ b/tests/ForkTest.php @@ -11,7 +11,7 @@ ) )->toEqual([2, 4]); -it('will execute the given closure with concurrency cap ', function () { +it('will execute the given closure with concurrency cap', function () { $results = Fork::new() ->concurrent(2) ->run(