2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
2016-08-16 06:46:26 +02:00
|
|
|
|
2016-05-24 05:48:28 +02:00
|
|
|
namespace Amp\Internal;
|
2016-05-21 16:44:52 +02:00
|
|
|
|
2017-01-07 13:47:45 +01:00
|
|
|
use AsyncInterop\Promise;
|
2016-05-21 16:44:52 +02:00
|
|
|
|
|
|
|
/**
|
2016-11-14 20:59:21 +01:00
|
|
|
* An promise that cannot be externally resolved. Used by Deferred in development mode.
|
2016-06-01 19:18:11 +02:00
|
|
|
*
|
|
|
|
* @internal
|
2016-05-21 16:44:52 +02:00
|
|
|
*/
|
2016-11-14 20:59:21 +01:00
|
|
|
final class PrivatePromise implements Promise {
|
2016-05-22 20:24:39 +02:00
|
|
|
use Placeholder;
|
2016-05-21 16:44:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param callable(callable $resolve, callable $reject): void $resolver
|
|
|
|
*/
|
|
|
|
public function __construct(callable $resolver) {
|
|
|
|
/**
|
2016-11-14 20:59:21 +01:00
|
|
|
* Resolves the promise with the given promise or value.
|
2016-05-21 16:44:52 +02:00
|
|
|
*
|
2016-05-22 20:24:39 +02:00
|
|
|
* @param mixed $value
|
2016-05-21 16:44:52 +02:00
|
|
|
*/
|
|
|
|
$resolve = function ($value = null) {
|
|
|
|
$this->resolve($value);
|
|
|
|
};
|
2017-01-07 13:47:45 +01:00
|
|
|
|
2016-05-21 16:44:52 +02:00
|
|
|
/**
|
2016-11-14 20:59:21 +01:00
|
|
|
* Fails the promise with the given exception.
|
2016-05-21 16:44:52 +02:00
|
|
|
*
|
2016-08-11 21:35:58 +02:00
|
|
|
* @param \Throwable $reason
|
2016-05-21 16:44:52 +02:00
|
|
|
*/
|
2016-08-11 21:35:58 +02:00
|
|
|
$fail = function (\Throwable $reason) {
|
2016-05-21 16:44:52 +02:00
|
|
|
$this->fail($reason);
|
|
|
|
};
|
|
|
|
|
2016-12-16 00:34:30 +01:00
|
|
|
$resolver($resolve, $fail);
|
2016-05-21 16:44:52 +02:00
|
|
|
}
|
|
|
|
}
|