/** * @param string $method * @return \Closure */ function hasMethod($method) { if (!is_string($method)) { return never(); } return combine(pool(isObject(), combine(isString(), 'class_exists')), function ($object) use($method) { return method_exists($object, $method); }); }
/** * @coroutine * * Enqueues a task to be executed by the worker pool. * * @param TaskInterface $task The task to enqueue. * * @return \Generator * * @resolve mixed The return value of the task. */ function enqueue(TaskInterface $task) { return pool()->enqueue($task); }
for ($i = 0; $i < $poolnum; $i++) { $pid = pcntl_fork(); if ($pid < 0) { tlog("fork error"); } else { if ($pid == 0) { tlog("child "); break; } else { tlog("father "); } } } work(); } function work() { tlog("work"); } function wait() { global $fatherpid; if (posix_getpid() == $fatherpid) { tlog("begin wait"); while (($pid = pcntl_wait($stat)) > 0) { tlog("child." . $pid . ". terminated \n"); } } } pool(); wait();
/** * Gets a worker from the global worker pool. * * @return \Icicle\Concurrent\Worker\Worker */ function get() : Worker { return pool()->get(); }