1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00
amp/lib/Internal/PrivateAwaitable.php
Aaron Piotrowski 69ec812bc0 Require PHP 7
2016-08-11 14:52:40 -05:00

44 lines
1007 B
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 \Throwable $reason
*/
$fail = function (\Throwable $reason) {
$this->fail($reason);
};
try {
$resolver($resolve, $fail);
} catch (\Throwable $exception) {
$this->fail($exception);
}
}
}