Skip to content

Commit ed66291

Browse files
authored
Merge pull request #152 from mcg-web/add-hooks-while-completing-sync-promise
Add hooks to helps promise completion with custom backend
2 parents 9d150c7 + 1c14336 commit ed66291

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Executor/Promise/Adapter/SyncPromiseAdapter.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function($value) use ($index, &$count, $total, &$result, $all) {
126126
*/
127127
public function wait(Promise $promise)
128128
{
129+
$this->beforeWait($promise);
129130
$dfdQueue = Deferred::getQueue();
130131
$promiseQueue = SyncPromise::getQueue();
131132

@@ -135,6 +136,7 @@ public function wait(Promise $promise)
135136
) {
136137
Deferred::runQueue();
137138
SyncPromise::runQueue();
139+
$this->onWait($promise);
138140
}
139141

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

149151
throw new InvariantViolation("Could not resolve promise");
150152
}
153+
154+
/**
155+
* Execute just before starting to run promise completion
156+
*
157+
* @param Promise $promise
158+
*/
159+
protected function beforeWait(Promise $promise)
160+
{
161+
}
162+
163+
/**
164+
* Execute while running promise completion
165+
*
166+
* @param Promise $promise
167+
*/
168+
protected function onWait(Promise $promise)
169+
{
170+
}
151171
}

0 commit comments

Comments
 (0)