Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
Línea -... Línea 2...
-
 
2
 
-
 
3
declare(strict_types=1);
2
 
4
 
Línea 3... Línea 5...
3
namespace GuzzleHttp\Promise;
5
namespace GuzzleHttp\Promise;
4
 
6
 
5
/**
7
/**
6
 * A task queue that executes tasks in a FIFO order.
8
 * A task queue that executes tasks in a FIFO order.
7
 *
9
 *
8
 * This task queue class is used to settle promises asynchronously and
10
 * This task queue class is used to settle promises asynchronously and
9
 * maintains a constant stack size. You can use the task queue asynchronously
11
 * maintains a constant stack size. You can use the task queue asynchronously
10
 * by calling the `run()` function of the global task queue in an event loop.
12
 * by calling the `run()` function of the global task queue in an event loop.
-
 
13
 *
-
 
14
 *     GuzzleHttp\Promise\Utils::queue()->run();
11
 *
15
 *
12
 *     GuzzleHttp\Promise\Utils::queue()->run();
16
 * @final
13
 */
17
 */
14
class TaskQueue implements TaskQueueInterface
18
class TaskQueue implements TaskQueueInterface
15
{
19
{
Línea 16... Línea 20...
16
    private $enableShutdown = true;
20
    private $enableShutdown = true;
17
    private $queue = [];
21
    private $queue = [];
18
 
22
 
19
    public function __construct($withShutdown = true)
23
    public function __construct(bool $withShutdown = true)
20
    {
24
    {
21
        if ($withShutdown) {
25
        if ($withShutdown) {
22
            register_shutdown_function(function () {
26
            register_shutdown_function(function (): void {
23
                if ($this->enableShutdown) {
27
                if ($this->enableShutdown) {
24
                    // Only run the tasks if an E_ERROR didn't occur.
28
                    // Only run the tasks if an E_ERROR didn't occur.
Línea 29... Línea 33...
29
                }
33
                }
30
            });
34
            });
31
        }
35
        }
32
    }
36
    }
Línea 33... Línea 37...
33
 
37
 
34
    public function isEmpty()
38
    public function isEmpty(): bool
35
    {
39
    {
36
        return !$this->queue;
40
        return !$this->queue;
Línea 37... Línea 41...
37
    }
41
    }
38
 
42
 
39
    public function add(callable $task)
43
    public function add(callable $task): void
40
    {
44
    {
Línea 41... Línea 45...
41
        $this->queue[] = $task;
45
        $this->queue[] = $task;
42
    }
46
    }
43
 
47
 
44
    public function run()
48
    public function run(): void
45
    {
49
    {
46
        while ($task = array_shift($this->queue)) {
50
        while ($task = array_shift($this->queue)) {
Línea 58... Línea 62...
58
     * MUST either run the task queue (as a result of running your event loop
62
     * MUST either run the task queue (as a result of running your event loop
59
     * or manually using the run() method) or wait on each outstanding promise.
63
     * or manually using the run() method) or wait on each outstanding promise.
60
     *
64
     *
61
     * Note: This shutdown will occur before any destructors are triggered.
65
     * Note: This shutdown will occur before any destructors are triggered.
62
     */
66
     */
63
    public function disableShutdown()
67
    public function disableShutdown(): void
64
    {
68
    {
65
        $this->enableShutdown = false;
69
        $this->enableShutdown = false;
66
    }
70
    }
67
}
71
}