public function __construct(callable $resolver)
{
/**
* Resolves the promise with the given promise or value.
*
* @param mixed $value
*/
$resolve = function ($value = null) {
$this->resolve($value);
};
/**
* Fails the promise with the given exception.
*
* @param \Throwable $reason
*/
$fail = function (\Throwable $reason) {
$this->fail($reason);
};
try {
$resolver($resolve, $fail);
} catch (\Throwable $exception) {
$this->fail($exception);
}
}