mirror of
https://github.com/danog/amp.git
synced 2024-12-03 01:47:49 +01:00
40 lines
877 B
PHP
40 lines
877 B
PHP
<?php
|
|
|
|
namespace Amp\Internal;
|
|
|
|
use AsyncInterop\Promise;
|
|
|
|
/**
|
|
* An promise that cannot be externally resolved. Used by Deferred in development mode.
|
|
*
|
|
* @internal
|
|
*/
|
|
final class PrivatePromise implements Promise {
|
|
use Placeholder;
|
|
|
|
/**
|
|
* @param callable(callable $resolve, callable $reject): void $resolver
|
|
*/
|
|
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);
|
|
};
|
|
|
|
$resolver($resolve, $fail);
|
|
}
|
|
}
|