Open Journal Systems  3.3.0
TaskQueue.php
1 <?php
2 namespace GuzzleHttp\Promise;
3 
13 class TaskQueue implements TaskQueueInterface
14 {
15  private $enableShutdown = true;
16  private $queue = [];
17 
18  public function __construct($withShutdown = true)
19  {
20  if ($withShutdown) {
21  register_shutdown_function(function () {
22  if ($this->enableShutdown) {
23  // Only run the tasks if an E_ERROR didn't occur.
24  $err = error_get_last();
25  if (!$err || ($err['type'] ^ E_ERROR)) {
26  $this->run();
27  }
28  }
29  });
30  }
31  }
32 
33  public function isEmpty()
34  {
35  return !$this->queue;
36  }
37 
38  public function add(callable $task)
39  {
40  $this->queue[] = $task;
41  }
42 
43  public function run()
44  {
46  while ($task = array_shift($this->queue)) {
47  $task();
48  }
49  }
50 
62  public function disableShutdown()
63  {
64  $this->enableShutdown = false;
65  }
66 }
GuzzleHttp\Promise\TaskQueue\disableShutdown
disableShutdown()
Definition: TaskQueue.php:62
GuzzleHttp\Promise\queue
queue(TaskQueueInterface $assign=null)
Definition: guzzlehttp/promises/src/functions.php:21
GuzzleHttp\Promise\TaskQueue\__construct
__construct($withShutdown=true)
Definition: TaskQueue.php:18
GuzzleHttp\Promise\TaskQueue\add
add(callable $task)
Definition: TaskQueue.php:38
GuzzleHttp\Promise\TaskQueue\run
run()
Definition: TaskQueue.php:43
GuzzleHttp\Promise\TaskQueue
Definition: TaskQueue.php:13
GuzzleHttp\Promise\TaskQueue\isEmpty
isEmpty()
Definition: TaskQueue.php:33
GuzzleHttp\Promise\TaskQueueInterface
Definition: TaskQueueInterface.php:4
GuzzleHttp\Promise
Definition: AggregateException.php:2