mirror of
https://github.com/danog/amp.git
synced 2025-01-22 05:11:42 +01:00
Fix coroutine fatal if initial advance errored
This commit is contained in:
parent
0c0395f7a0
commit
5e7d6ff095
@ -497,6 +497,8 @@ function resolve(\Generator $generator, Reactor $reactor = null, callable $promi
|
||||
$cs->promisifier = $promisifier;
|
||||
$cs->returnValue = null;
|
||||
$cs->currentPromise = null;
|
||||
$cs->isResolved = false;
|
||||
|
||||
__coroutineAdvance($cs);
|
||||
|
||||
return $cs->promisor->promise();
|
||||
@ -520,18 +522,19 @@ function __coroutineAdvance($cs) {
|
||||
} elseif ($cs->promisifier) {
|
||||
__coroutineCustomPromisify($cs, $key, $yielded);
|
||||
} else {
|
||||
$promisor = $cs->promisor;
|
||||
$cs->promisor = null;
|
||||
$promisor->fail(new \DomainException(
|
||||
$cs->isResolved = true;
|
||||
$cs->promisor->fail(new \DomainException(
|
||||
__coroutineYieldError($key, $yielded)
|
||||
));
|
||||
return;
|
||||
}
|
||||
$cs->reactor->immediately("Amp\__coroutineNextTick", ["cb_data" => $cs]);
|
||||
} catch (\Exception $uncaught) {
|
||||
if ($promisor = $cs->promisor) {
|
||||
$cs->promisor = null;
|
||||
$promisor->fail($uncaught);
|
||||
if ($cs->isResolved) {
|
||||
throw new \RuntimeException("", 0, $uncaught);
|
||||
} else {
|
||||
$cs->isResolved = true;
|
||||
$cs->promisor->fail($uncaught);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -566,9 +569,11 @@ function __coroutineSend($error, $result, $cs) {
|
||||
}
|
||||
__coroutineAdvance($cs);
|
||||
} catch (\Exception $uncaught) {
|
||||
if ($promisor = $cs->promisor) {
|
||||
$cs->promisor = null;
|
||||
$promisor->fail($uncaught);
|
||||
if ($cs->isResolved) {
|
||||
throw new \RuntimeException("", 0, $uncaught);
|
||||
} else {
|
||||
$cs->isResolved = true;
|
||||
$cs->promisor->fail($uncaught);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user