PHP code example of react-parallel / future-to-promise-converter

1. Go to this page and download the library: Download react-parallel/future-to-promise-converter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

react-parallel / future-to-promise-converter example snippets


use parallel\Future;
use parallel\Runtime;
use React\EventLoop\Factory;
use ReactParallel\FutureToPromiseConverter\FutureToPromiseConverter;

$loop = Factory::create();
$converter = new FutureToPromiseConverter($loop);

$runtime = new Runtime('vendor/autoload.php');

/** @var Future $future */
$future = $runtime->run(function () {
    sleep(3);

    return 3;
});

$converter->convert($future)->done(function ($value) {
    // $value will be 3 here
});