1 | <?php |
||
21 | class Async |
||
22 | { |
||
23 | /** |
||
24 | * A pool manage async processes. |
||
25 | * |
||
26 | * @var Pool |
||
27 | */ |
||
28 | protected $pool; |
||
29 | |||
30 | /** |
||
31 | * Event dispatcher manage async events. |
||
32 | * |
||
33 | * @var EventDispatcher |
||
34 | */ |
||
35 | protected $events; |
||
36 | |||
37 | /** |
||
38 | * Create a new Async instance. |
||
39 | * |
||
40 | * @param \VXM\Async\Pool $pool |
||
41 | * @param \Illuminate\Contracts\Events\Dispatcher $events |
||
42 | */ |
||
43 | public function __construct(Pool $pool, EventDispatcher $events) |
||
48 | |||
49 | /** |
||
50 | * Execute async job. |
||
51 | * |
||
52 | * @param callable|string|object $job need to execute. |
||
53 | * @param array $events event. Have key is an event name, value is a callable triggered when event |
||
54 | * happen, have three events `error`, `success`, `timeout`. |
||
55 | * @param int|null $outputLength |
||
56 | * @return static |
||
57 | */ |
||
58 | public function run($job, array $events = [], int $outputLength = null): self |
||
70 | |||
71 | /** |
||
72 | * Batch execute async jobs. |
||
73 | * |
||
74 | * @param array $jobs |
||
75 | * @return static |
||
76 | * @see run() |
||
77 | * @since 2.0.0 |
||
78 | */ |
||
79 | public function batchRun(...$jobs): self |
||
98 | |||
99 | /** |
||
100 | * Wait until all async jobs done and return job results. |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | public function wait() |
||
111 | |||
112 | /** |
||
113 | * Make async job. |
||
114 | * |
||
115 | * @param $job |
||
116 | * |
||
117 | * @return mixed |
||
118 | */ |
||
119 | protected function makeJob($job) |
||
127 | |||
128 | /** |
||
129 | * Create class and method job. |
||
130 | * |
||
131 | * @param string $job |
||
132 | * |
||
133 | * @return Closure |
||
134 | */ |
||
135 | protected function createClassJob(string $job): Closure |
||
143 | |||
144 | /** |
||
145 | * Listen events of process given. |
||
146 | * |
||
147 | * @param array $events |
||
148 | * @param Runnable $process |
||
149 | */ |
||
150 | protected function addProcessListeners(array $events, Runnable $process): void |
||
156 | |||
157 | /** |
||
158 | * Make a base listener for integration with [[EventDispatcher]]. |
||
159 | * |
||
160 | * @param string $event |
||
161 | * @param Runnable $process |
||
162 | * |
||
163 | * @return callable |
||
164 | */ |
||
165 | protected function makeProcessListener(string $event, Runnable $process): callable |
||
173 | |||
174 | /** |
||
175 | * Create a new process for run a job. |
||
176 | * |
||
177 | * @param callable $job need to execute. |
||
178 | * |
||
179 | * @return Runnable process. |
||
180 | * @deprecated since 2.1.0 |
||
181 | */ |
||
182 | protected function createProcess($job): Runnable |
||
186 | |||
187 | /** |
||
188 | * Get current pool. |
||
189 | * |
||
190 | * @return Pool |
||
191 | * @since 2.1.0 |
||
192 | */ |
||
193 | public function getPool(): Pool |
||
197 | } |
||
198 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.