diff --git a/src/Forking/Fork.php b/src/Forking/Fork.php index ee974cb..d2893b9 100644 --- a/src/Forking/Fork.php +++ b/src/Forking/Fork.php @@ -80,7 +80,7 @@ class Fork implements ContextInterface */ public function isRunning() { - return 0 !== $this->pid && posix_getpgid($this->pid) !== false; + return 0 !== $this->pid && false !== posix_getpgid($this->pid); } /** @@ -146,9 +146,12 @@ class Fork implements ContextInterface $executor = new ForkExecutor($this->synchronized, $channel); try { - $function = $this->function; - if ($function instanceof \Closure) { - $function = $function->bindTo($executor, ForkExecutor::class); + if ($this->function instanceof \Closure) { + $function = $this->function->bindTo($executor, ForkExecutor::class); + } + + if (empty($function)) { + $function = $this->function; } $result = new ExitSuccess(yield call_user_func_array($function, $this->args)); diff --git a/src/Threading/InternalThread.php b/src/Threading/InternalThread.php index 9928e39..005d605 100644 --- a/src/Threading/InternalThread.php +++ b/src/Threading/InternalThread.php @@ -120,9 +120,12 @@ class InternalThread extends \Thread $executor = new ThreadExecutor($this, $channel); try { - $function = $this->function; - if ($function instanceof \Closure) { - $function = $function->bindTo($executor, ThreadExecutor::class); + if ($this->function instanceof \Closure) { + $function = $this->function->bindTo($executor, ThreadExecutor::class); + } + + if (empty($function)) { + $function = $this->function; } $result = new ExitSuccess(yield call_user_func_array($function, $this->args));