Uh oh!
There was an error while loading. Please reload this page.
Support promise cancellation - #18
Conversation
jsor
commented
Feb 24, 2016
👍 For the record (not suitable right now because it'd be a BC), i recommend to not typehint against namespaceReact\Promise\Timer;
useReact\EventLoop\LoopInterface;
useReact\Promise;
functiontimeout($input, $time, LoopInterface$loop)
{
$promise = Promise\resolve($input);
returnnewPromise\Promise(function ($resolve, $reject) use ($loop, $time, $promise) {
$timer = $loop->addTimer($time, function () use ($time, $promise, $reject) {
$reject(newTimeoutException($time, 'Timed out after ' . $time . ' seconds'));
$promise->cancel();
});
$promise->then(function ($v) use ($timer, $loop, $resolve) {
$loop->cancelTimer($timer);
$resolve($v);
}, function ($v) use ($timer, $loop, $reject) {
$loop->cancelTimer($timer);
$reject($v);
});
}, array($promise, 'cancel'));
}The advantages are, that you can remove a few |
jsor
commented
Feb 24, 2016
My, bad. I see now that you're doing the |
clue
commented
Feb 25, 2016
clue
commented
Feb 26, 2016
I'd like to get in reactphp/promise#48 first so that we can rely on cancellation support to be present in all installations and hence make this feature more predictable. An update to this PR is ready, I'll push this once the other PR is in and a v1.2.0 has been tagged. |
Cancellation support has been backported from promise v2.1 to v1.2, so we can now rely on cancellation support being available for both major versions.
clue
commented
Feb 28, 2016
The linked PR is now in and I've updated this PR to make this feature more consistently available. Ready for review |
WyriHaximus
commented
Feb 29, 2016
LGTM |
jsor
commented
Feb 29, 2016
|
resolve()andreject()RuntimeExceptiontimeout()timeout()is not affectedCloses#3, supersedes/closes#13