Created
December 19, 2012 16:24
-
-
Save CHH/4337978 to your computer and use it in GitHub Desktop.
React Promise + libuv fun!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"react/promise": "*@dev" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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