コード例 #1
0
/**
 * @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);
    });
}
コード例 #2
0
ファイル: functions.php プロジェクト: Nik-ADA/concurrent
 /**
  * @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);
 }
コード例 #3
0
    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();
コード例 #4
0
ファイル: functions.php プロジェクト: icicleio/concurrent
 /**
  * Gets a worker from the global worker pool.
  *
  * @return \Icicle\Concurrent\Worker\Worker
  */
 function get() : Worker
 {
     return pool()->get();
 }