PHP code example of labrador-kennel / composite-future

1. Go to this page and download the library: Download labrador-kennel/composite-future 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/ */

    

labrador-kennel / composite-future example snippets




namespace Acme\Demo;

use Amp\Future;
use Labrador\CompositeFuture\CompositeFuture;

function futuresGeneratingMethod() : CompositeFuture {
    $futures = ['a' => Future::complete(1), 'b' => Future::complete(2), 'c' => Future::error(new \Exception('something went wrong'))];
    return new CompositeFuture($futures);
}

$futures = futuresGeneratingMethod();
// Returns an array with keys equal to the index of the Future and the value to the Future resolution
// Will throw an exception when an error is encountered
$futures->await();

// Also has access to the following methods, which follow the same documentation as their corresponding
// Amp\Future functions.
$futures->awaitAll();
$futures->awaitAny();
$futures->awaitAnyN(2);
$futures->awaitFirst();