if (!
$handlers) { return;
} // If the value was not a settled promise or a thenable, then resolve
// it in the task queue using the correct ID.
if (!
is_object($value) || !
method_exists($value, 'then'
)) { $id =
$state === self::FULFILLED ? 1 : 2;
// It's a success, so resolve the handlers in the queue.
Utils::
queue()->
add(static function D
) use ($id,
$value,
$handlers): void
{ foreach ($handlers as $handler) { self::
callHandler($id,
$value,
$handler);
} });
} elseif ($value instanceof Promise && Is::
pending($value)) { // We can just merge our handlers onto the next promise.
$value->handlers =
array_merge($value->handlers,
$handlers);
} else { // Resolve the handlers when the forwarded promise is resolved.
$value->
then( static function D
$value) use ($handlers): void
{ foreach ($handlers as $handler) { self::
callHandler(1,
$value,
$handler);
}