Skip to content

Commit

Permalink
Revert "Simplify queue draining code"
Browse files Browse the repository at this point in the history
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
jsor committed Sep 14, 2015
1 parent cc6f1c3 commit 239c075
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Queue/SynchronousQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@joshdifabio

joshdifabio Apr 29, 2016

Contributor

Variable function calls do not work for Class::method callables prior to PHP7. You need to use call_user_func() to support all callables.

This comment has been minimized.

Copy link
@jsor

jsor Apr 29, 2016

Author Member

We're doing $func() all over the place. If anything, we should change it everywhere.

} catch (\Exception $exception) {

This comment has been minimized.

Copy link
@joshdifabio

joshdifabio Apr 29, 2016

Contributor

Please also catch \Throwable.

This comment has been minimized.

Copy link
@jsor

jsor Apr 29, 2016

Author Member

Done (0865eac).

}

unset($this->queue[$i]);

if ($exception) {
throw $exception;
}
}

$this->queue = [];
}
}

0 comments on commit 239c075

Please sign in to comment.