Skip to content

Commit 06aa368

Browse files
committed
Add $kill_childs argument
1 parent 15721c5 commit 06aa368

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Pool.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class Pool{
1010

1111
protected int $max_childs;
12+
protected bool $kill_childs;
1213
protected array $childs = [];
1314
protected array $queue = [];
1415
protected int $pid;
@@ -18,14 +19,15 @@ class Pool{
1819
private bool $is_resolving_queue = false;
1920
private bool $need_tick = true;
2021

21-
public function __construct(?int $max_childs = null)
22+
public function __construct(?int $max_childs = null, bool $kill_childs = true)
2223
{
2324
if(!extension_loaded("pcntl")){
2425
throw new MissingExtensionException("PCNTL Extension is missing in your PHP build");
2526
}
2627
$this->pid = getmypid();
2728
$max_childs ??= (self::getCoresCount() ?? 1) * 50;
2829
$this->max_childs = $max_childs;
30+
$this->kill_childs = $kill_childs;
2931

3032
register_tick_function([$this, "tick"]);
3133
pcntl_signal(SIGCHLD, SIG_IGN); // ignores the SIGCHLD signal
@@ -74,7 +76,9 @@ protected function _parallel(Closure $closure, ...$args)
7476
else{
7577
// we are the child
7678
$this->is_parent = false;
77-
pcntl_signal(SIGINT, SIG_IGN);
79+
if (!$this->kill_childs) {
80+
pcntl_signal(SIGINT, SIG_IGN);
81+
}
7882
$closure($args);
7983
exit;
8084
}

0 commit comments

Comments
 (0)