mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Amp\Internal;
|
|
|
|
use Interop\Async\Awaitable;
|
|
|
|
/**
|
|
* An awaitable that cannot be externally resolved. Used by Deferred in development mode.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class PrivateAwaitable implements Awaitable {
|
|
use Placeholder;
|
|
|
|
/**
|
|
* @param callable(callable $resolve, callable $reject): void $resolver
|
|
*/
|
|
public function __construct(callable $resolver) {
|
|
/**
|
|
* Resolves the awaitable with the given awaitable or value.
|
|
*
|
|
* @param mixed $value
|
|
*/
|
|
$resolve = function ($value = null) {
|
|
$this->resolve($value);
|
|
};
|
|
|
|
/**
|
|
* Fails the awaitable with the given exception.
|
|
*
|
|
* @param \Exception $reason
|
|
*/
|
|
$fail = function ($reason) {
|
|
$this->fail($reason);
|
|
};
|
|
|
|
try {
|
|
$resolver($resolve, $fail);
|
|
} catch (\Throwable $exception) {
|
|
$this->fail($exception);
|
|
} catch (\Exception $exception) {
|
|
$this->fail($exception);
|
|
}
|
|
}
|
|
}
|