mirror of
https://github.com/danog/amp.git
synced 2024-11-26 20:15:00 +01:00
Cleaner resolution
This commit is contained in:
parent
92767755ee
commit
4ed8e65468
@ -54,12 +54,14 @@ trait Placeholder {
|
||||
|
||||
if (null === $this->onResolved) {
|
||||
$this->onResolved = $onResolved;
|
||||
} elseif (!$this->onResolved instanceof WhenQueue) {
|
||||
$this->onResolved = new WhenQueue($this->onResolved);
|
||||
$this->onResolved->push($onResolved);
|
||||
} else {
|
||||
$this->onResolved->push($onResolved);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->onResolved instanceof WhenQueue) {
|
||||
$this->onResolved = new WhenQueue($this->onResolved);
|
||||
}
|
||||
|
||||
$this->onResolved->push($onResolved);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,12 +75,19 @@ trait Placeholder {
|
||||
$this->resolved = true;
|
||||
$this->result = $value;
|
||||
|
||||
if ($this->onResolved !== null) {
|
||||
if ($this->result instanceof Awaitable) {
|
||||
$this->result->when($this->onResolved);
|
||||
} else {
|
||||
try {
|
||||
if ($this->onResolved === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$onResolved = $this->onResolved;
|
||||
$this->onResolved = null;
|
||||
|
||||
if ($this->result instanceof Awaitable) {
|
||||
$this->result->when($onResolved);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$onResolved(null, $this->result);
|
||||
} catch (\Throwable $exception) {
|
||||
Loop::defer(static function () use ($exception) {
|
||||
@ -91,10 +100,6 @@ trait Placeholder {
|
||||
}
|
||||
}
|
||||
|
||||
$this->onResolved = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable|\Exception $reason
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user