-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Simplify queue draining code"
This reverts commit cc6f1c3. Note: The task must be kept on the queue until after it is called. Otherwise drain() will be called recursively.
- Loading branch information
Showing
1 changed file
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,23 @@ public function enqueue(callable $task) | |
|
||
private function drain() | ||
{ | ||
/** @var callable $task */ | ||
while ($task = array_shift($this->queue)) { | ||
$task(); | ||
for ($i = key($this->queue); isset($this->queue[$i]); $i++) { | ||
$task = $this->queue[$i]; | ||
|
||
$exception = null; | ||
|
||
try { | ||
$task(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jsor
Author
Member
|
||
} catch (\Exception $exception) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
unset($this->queue[$i]); | ||
|
||
if ($exception) { | ||
throw $exception; | ||
} | ||
} | ||
|
||
$this->queue = []; | ||
} | ||
} |
Variable function calls do not work for
Class::method
callables prior to PHP7. You need to usecall_user_func()
to support all callables.