From 1c143360ca5fbb5d72246e37652fa07cc9502f9f Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 18 Aug 2017 16:18:48 +0200 Subject: [PATCH] Add hooks to helps promise completion with custom backend --- .../Promise/Adapter/SyncPromiseAdapter.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Executor/Promise/Adapter/SyncPromiseAdapter.php b/src/Executor/Promise/Adapter/SyncPromiseAdapter.php index 35341b3..44ddf66 100644 --- a/src/Executor/Promise/Adapter/SyncPromiseAdapter.php +++ b/src/Executor/Promise/Adapter/SyncPromiseAdapter.php @@ -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) + { + } }