« parallel\Runtime::kill
parallel\Future::cancel »

The parallel\Future class

(0.8.0)

Futures

A Future represents the return value or uncaught exception from a task, and exposes an API for cancellation.

例1 Example showing Future as return value

<?php
$runtime = new \parallel\Runtime;
$future  = $runtime->run(function(){
    return "World";
});
printf("Hello %s\n", $future->value());
?>

上の例の出力は、 たとえば以下のようになります。

Hello World

The behaviour of a future also allows it to be used as a simple synchronization point even where the task does not return a value explicitly.

例2 Example showing Future as synchronization point

<?php
$runtime = new \parallel\Runtime;
$future  = $runtime->run(function(){
    echo "in child ";
    for ($i = 0; $i < 500; $i++) {
        if ($i % 10 == 0) {
            echo ".";
        }
    }
    echo " leaving child";
});

$future->value();
echo "\nparent continues\n";
?>

上の例の出力は、 たとえば以下のようになります。

in child .................................................. leaving child
parent continues

クラス概要

final class parallel\Future {
/* Resolution */
public function value(): mixed
/* State */
public function cancelled(): bool
public function done(): bool
/* Cancellation */
public function cancel(): bool
}

目次

関連キーワード:
parallel   Future   future   return   runtime   child   Runtime   cancel   State   task   Example   showing   World   Hello   synchronization   point   leaving   continues   Resolution   cancelled   Cancellation   Detection   kill   Futures   represents
関連する関数・ページ:
parallel-future.done   parallel-future.cancelled   parallel-future.cancel   parallel-future.value   class.parallel-runtime   parallel-runtime.kill