I was playing around with React and wanted to try to get a working timeout function. Following (sort of) the examples and Unit tests from https://github.com/reactphp/promise-timer#timeout I came up with:
use React\Promise\Timer;
$promise = uncertainOperation();
$loop = \React\EventLoop\Factory::create();
Timer\timeout($promise, 1, $loop)->then(
function ($value) {
var_dump($value);
}
,
function ($error) {
var_dump($error);
}
);
$loop->run();
function uncertainOperation() {
return new React\Promise\Promise(
function ($resolve) {
for($i = 0; $i < 30000000; $i++) { }
$resolve("Done");
}
);
}
But this always resolves with "Done" no matter how low I set the time in Timer\timeout. What am I missing?