Skip to content

Commit

Permalink
Merge pull request #152 from mcg-web/add-hooks-while-completing-sync-…
Browse files Browse the repository at this point in the history
…promise

Add hooks to helps promise completion with custom backend
  • Loading branch information
vladar authored Aug 18, 2017
2 parents 9d150c7 + 1c14336 commit ed66291
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Executor/Promise/Adapter/SyncPromiseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function($value) use ($index, &$count, $total, &$result, $all) {
*/
public function wait(Promise $promise)
{
$this->beforeWait($promise);
$dfdQueue = Deferred::getQueue();
$promiseQueue = SyncPromise::getQueue();

Expand All @@ -135,6 +136,7 @@ public function wait(Promise $promise)
) {
Deferred::runQueue();
SyncPromise::runQueue();
$this->onWait($promise);
}

/** @var SyncPromise $syncPromise */
Expand All @@ -148,4 +150,22 @@ public function wait(Promise $promise)

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)
{
}
}

0 comments on commit ed66291

Please sign in to comment.