public function createDeferred()
{
$promise = null;
return new DeferredBridge(['getPromise' => function () use(&$promise) {
if (!$promise) {
throw new Exception(sprintf("[%s] must be rejected before obtaining the promise.", PromiseRejected::class));
}
return $promise;
}, 'resolve' => function () {
throw new Exception(sprintf("You cannot call resolve() for [%s].", PromiseRejected::class));
}, 'reject' => function ($reason = null) use(&$promise) {
if (!$promise) {
$promise = new PromiseRejected($reason);
}
}, 'cancel' => function () {
throw new Exception(sprintf("You cannot call cancel() for [%s].", PromiseRejected::class));
}]);
}