PHP code example of icicleio / icicle
1. Go to this page and download the library: Download icicleio/icicle 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/ */
icicleio / icicle example snippets
#!/usr/bin/env php
e Icicle\Coroutine\Coroutine;
use Icicle\Loop;
$generator = function () {
try {
// Sets $start to the value returned by microtime() after approx. 1 second.
$start = (yield Awaitable\resolve(microtime(true))->delay(1));
echo "Sleep time: ", microtime(true) - $start, "\n";
// Throws the exception from the rejected promise into the coroutine.
yield Awaitable\reject(new Exception('Rejected promise'));
} catch (Exception $e) { // Catches promise rejection reason.
echo "Caught exception: ", $e->getMessage(), "\n";
}
yield Awaitable\resolve('Coroutine completed');
};
$coroutine = new Coroutine($generator());
$coroutine->done(function ($data) {
echo $data, "\n";
});
Loop\run();