Skip to content

Instantly share code, notes, and snippets.

@CHH
Created December 19, 2012 16:24
Show Gist options
  • Save CHH/4337978 to your computer and use it in GitHub Desktop.
Save CHH/4337978 to your computer and use it in GitHub Desktop.
React Promise + libuv fun!
{
"require": {
"react/promise": "*@dev"
}
}
<?php
require(__DIR__ . '/vendor/autoload.php');
# From react/promise package
use React\Promise\Deferred;
function asyncSleep($seconds)
{
$t = uv_timer_init();
$d = new Deferred;
uv_timer_start($t, $seconds * 1000, 0, [$d, 'resolve']);
return $d->promise();
}
asyncSleep(2)->then(function() {
echo "First\n";
return asyncSleep(3);
})->then(function() {
echo "Ready\n";
});
uv_run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment