1 | <?php |
||
81 | class Async extends Component |
||
82 | { |
||
83 | |||
84 | /** |
||
85 | * @event SuccessEvent an event that is triggered when task done. |
||
86 | */ |
||
87 | const EVENT_SUCCESS = 'success'; |
||
88 | |||
89 | /** |
||
90 | * @event ErrorEvent an event that is triggered when task error. |
||
91 | */ |
||
92 | const EVENT_ERROR = 'error'; |
||
93 | |||
94 | /** |
||
95 | * @event \yii\base\Event an event that is triggered when task timeout. |
||
96 | */ |
||
97 | const EVENT_TIMEOUT = 'timeout'; |
||
98 | |||
99 | /** |
||
100 | * @var Pool handling tasks. |
||
101 | */ |
||
102 | protected $pool; |
||
103 | |||
104 | /** |
||
105 | * @var string a file config of an application run in child process. |
||
106 | * Note: If an autoload file's set, it will not affect, you need to invoke an app in your autoload if needed. |
||
107 | */ |
||
108 | protected $appConfigFile; |
||
109 | |||
110 | /** |
||
111 | * Async constructor. |
||
112 | * |
||
113 | * @param array $config |
||
114 | * @throws \yii\base\InvalidConfigException |
||
115 | */ |
||
116 | 8 | public function __construct($config = []) |
|
123 | |||
124 | /** |
||
125 | * Execute async task. |
||
126 | * |
||
127 | * @param callable|\Spatie\Async\Task|Task $callable need to execute. |
||
128 | * @param array $callbacks event. Have key is an event name, value is a callable triggered when event happen, |
||
129 | * have three events `error`, `success`, `timeout`. |
||
130 | * @return static |
||
131 | */ |
||
132 | 8 | public function run($callable, array $callbacks = []): self |
|
159 | |||
160 | /** |
||
161 | * This method is called when task executed success. |
||
162 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
163 | * event is triggered. |
||
164 | * |
||
165 | * @param mixed $output of task executed. |
||
166 | * @throws \yii\base\InvalidConfigException |
||
167 | */ |
||
168 | 3 | public function success($output): void |
|
177 | |||
178 | /** |
||
179 | * This method is called when task executed error. |
||
180 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
181 | * event is triggered. |
||
182 | * |
||
183 | * @param Throwable $throwable when executing task. |
||
184 | * @throws \yii\base\InvalidConfigException |
||
185 | */ |
||
186 | 2 | public function error(Throwable $throwable): void |
|
195 | |||
196 | /** |
||
197 | * This method is called when task executed timeout. |
||
198 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
199 | * event is triggered. |
||
200 | * |
||
201 | * @throws \yii\base\InvalidConfigException |
||
202 | */ |
||
203 | 2 | public function timeout(): void |
|
209 | |||
210 | /** |
||
211 | * Wait until all tasks done. |
||
212 | */ |
||
213 | 7 | public function wait(): void |
|
217 | |||
218 | /** |
||
219 | * Set concurrency process do tasks. |
||
220 | * |
||
221 | * @param int $concurrency |
||
222 | */ |
||
223 | public function setConcurrency(int $concurrency): void |
||
227 | |||
228 | /** |
||
229 | * Set timeout of task when execute. |
||
230 | * |
||
231 | * @param int $timeout |
||
232 | */ |
||
233 | 8 | public function setTimeout(int $timeout): void |
|
237 | |||
238 | /** |
||
239 | * Set sleep time when wait tasks execute. |
||
240 | * |
||
241 | * @param int $sleepTimeWait |
||
242 | */ |
||
243 | public function setSleepTimeWait(int $sleepTimeWait): void |
||
247 | |||
248 | /** |
||
249 | * Set autoload for environment tasks execute. |
||
250 | * @param string $autoload it can use at an alias. |
||
251 | */ |
||
252 | public function setAutoload(string $autoload): void |
||
256 | |||
257 | /** |
||
258 | * Set an application config file for invoke in child runtime process. |
||
259 | * |
||
260 | * @param string $appConfigFile it can use at an alias. |
||
261 | */ |
||
262 | 8 | public function setAppConfigFile(string $appConfigFile): void |
|
266 | |||
267 | /** |
||
268 | * Create an async process with hooked events. |
||
269 | * |
||
270 | * @param callable|\Spatie\Async\Task|Task $callable need to execute. |
||
271 | * @return Runnable process. |
||
272 | */ |
||
273 | 8 | protected function createProcess($callable): Runnable |
|
280 | |||
281 | } |
||
282 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: