Merge pull request #152 from mcg-web/add-hooks-while-completing-sync-promise

Add hooks to helps promise completion with custom backend
This commit is contained in:
Vladimir Razuvaev 2017-08-18 22:30:03 +07:00 committed by GitHub
commit ed66291308

View File

@ -126,6 +126,7 @@ class SyncPromiseAdapter implements PromiseAdapter
*/
public function wait(Promise $promise)
{
$this->beforeWait($promise);
$dfdQueue = Deferred::getQueue();
$promiseQueue = SyncPromise::getQueue();
@ -135,6 +136,7 @@ class SyncPromiseAdapter implements PromiseAdapter
) {
Deferred::runQueue();
SyncPromise::runQueue();
$this->onWait($promise);
}
/** @var SyncPromise $syncPromise */
@ -148,4 +150,22 @@ class SyncPromiseAdapter implements PromiseAdapter
throw new InvariantViolation("Could not resolve promise");
}
/**
* Execute just before starting to run promise completion
*
* @param Promise $promise
*/
protected function beforeWait(Promise $promise)
{
}
/**
* Execute while running promise completion
*
* @param Promise $promise
*/
protected function onWait(Promise $promise)
{
}
}