コード例 #1
0
require 'vendor/autoload.php';
use FutoIn\RI\AsyncSteps;
use FutoIn\RI\ScopedSteps;
use FutoIn\RI\AsyncTool;
function dummy_service_read($success, $error)
{
    // We expect it calles success when data is available
    // and error, if error occurs
    // Returns some request handle
    return null;
}
function dummy_service_cancel($reqhandle)
{
    // We assume it cancels previously scheduled reqhandle
}
$root_as = new ScopedSteps();
$root_as->add(function ($as) {
    AsyncTool::callLater(function () use($as) {
        $as->success('async success()');
    });
    $as->setTimeout(10);
    // ms
})->add(function ($as, $arg) {
    echo $arg . PHP_EOL;
    $reqhandle = dummy_service_read(function ($data) use($as) {
        $as->success($data);
    }, function ($err) use($as) {
        if ($err !== 'SomeSpecificCancelCode') {
            $as->error($err);
        }
    });
コード例 #2
0
<?php

require 'vendor/autoload.php';
use FutoIn\RI\AsyncSteps;
use FutoIn\RI\ScopedSteps;
$root_as = new ScopedSteps();
$root_as->add(function ($as) {
    $as->success("MyValue");
})->add(function ($as, $arg) {
    if ($arg === 'MyValue') {
        $as->add(function ($as) {
            $as->error('MyError', 'Something bad has happened');
        });
    }
    $as->successStep();
}, function ($as, $err) {
    if ($err === 'MyError') {
        $as->success('NotSoBad');
    }
});
$root_as->add(function ($as, $arg) {
    if ($arg === 'NotSoBad') {
        echo 'MyError was ignored: ' . $as->state()->error_info . PHP_EOL;
    }
    $as->state()->p1arg = 'abc';
    $as->state()->p2arg = 'xyz';
    $p = $as->parallel();
    $p->add(function ($as) {
        echo 'Parallel Step 1' . PHP_EOL;
        $as->add(function ($as) {
            echo 'Parallel Step 1->1' . PHP_EOL;