PHP code example of rx / await

1. Go to this page and download the library: Download rx/await 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/ */

    

rx / await example snippets




//Do some aysnc craziness with observables
$observable = \Rx\Observable::interval(1000);

//Returns a `Generator` with the results of the observable
$generator = \Rx\await($observable);

//You can now use the results like a regular `Iterator`
foreach ($generator as $item) {

    //Will block here until the observable completes
    echo $item, PHP_EOL;
}





$source = \Rx\Observable::interval(1000)
    ->takeUntil(\Rx\Observable::timer(10000)); //timeout after 10 seconds

$generator = \Rx\await($source);

foreach ($generator as $item) {
    echo $item, PHP_EOL;
}

echo "DONE";



$source = \Rx\Observable::interval(1000)
    ->take(5); //Limit items to 5

$generator = \Rx\await($source);

foreach ($generator as $item) {
    echo $item, PHP_EOL;
}

echo "DONE";