Skip to content

Commit

Permalink
Merge pull request #48 from stevebauman/main
Browse files Browse the repository at this point in the history
Kill any forked tasks when force closed in terminal
  • Loading branch information
freekmurze authored Nov 23, 2023
2 parents 82a820f + 3e4c67a commit 5c38486
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Fork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ForkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5c38486

Please sign in to comment.