1 | <?php |
||
76 | class Async extends Component |
||
77 | { |
||
78 | |||
79 | /** |
||
80 | * @event SuccessEvent an event that is triggered when task done. |
||
81 | */ |
||
82 | const EVENT_SUCCESS = 'success'; |
||
83 | |||
84 | /** |
||
85 | * @event ErrorEvent an event that is triggered when task error. |
||
86 | */ |
||
87 | const EVENT_ERROR = 'error'; |
||
88 | |||
89 | /** |
||
90 | * @event \yii\base\Event an event that is triggered when task timeout. |
||
91 | */ |
||
92 | const EVENT_TIMEOUT = 'timeout'; |
||
93 | |||
94 | /** |
||
95 | * @var Pool handling tasks. |
||
96 | */ |
||
97 | protected $pool; |
||
98 | |||
99 | /** |
||
100 | * Async constructor. |
||
101 | * |
||
102 | * @param array $config |
||
103 | * @throws \yii\base\InvalidConfigException |
||
104 | */ |
||
105 | 5 | public function __construct($config = []) |
|
112 | |||
113 | /** |
||
114 | * Execute async task. |
||
115 | * |
||
116 | * @param callable|\Spatie\Async\Task|Task $callable need to execute. |
||
117 | * @param array $callbacks event. Have key is an event name, value is a callable triggered when event happen, |
||
118 | * have three events `error`, `success`, `timeout`. |
||
119 | * @return static |
||
120 | */ |
||
121 | 5 | public function run($callable, array $callbacks = []): self |
|
151 | |||
152 | /** |
||
153 | * This method is called when task executed success. |
||
154 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
155 | * event is triggered. |
||
156 | * |
||
157 | * @param mixed $output of task executed. |
||
158 | * @throws \yii\base\InvalidConfigException |
||
159 | */ |
||
160 | 2 | public function success($output): void |
|
169 | |||
170 | /** |
||
171 | * This method is called when task executed error. |
||
172 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
173 | * event is triggered. |
||
174 | * |
||
175 | * @param Throwable $throwable when executing task. |
||
176 | * @throws \yii\base\InvalidConfigException |
||
177 | */ |
||
178 | 1 | public function error(Throwable $throwable): void |
|
187 | |||
188 | /** |
||
189 | * This method is called when task executed timeout. |
||
190 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
191 | * event is triggered. |
||
192 | * |
||
193 | * @throws \yii\base\InvalidConfigException |
||
194 | */ |
||
195 | 1 | public function timeout(): void |
|
201 | |||
202 | /** |
||
203 | * Wait until all tasks done. |
||
204 | */ |
||
205 | 4 | public function wait(): void |
|
209 | |||
210 | /** |
||
211 | * Set concurrency process do tasks. |
||
212 | * |
||
213 | * @param int $concurrency |
||
214 | */ |
||
215 | public function setConcurrency(int $concurrency): void |
||
219 | |||
220 | /** |
||
221 | * Set timeout of task when execute. |
||
222 | * |
||
223 | * @param int $timeout |
||
224 | */ |
||
225 | 5 | public function setTimeout(int $timeout): void |
|
229 | |||
230 | /** |
||
231 | * Set sleep time when wait tasks execute. |
||
232 | * |
||
233 | * @param int $sleepTimeWait |
||
234 | */ |
||
235 | public function setSleepTimeWait(int $sleepTimeWait): void |
||
239 | |||
240 | /** |
||
241 | * Set autoload for environment tasks execute. |
||
242 | * @param string $autoload |
||
243 | */ |
||
244 | public function setAutoload(string $autoload): void |
||
248 | |||
249 | } |
||
250 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.