1 | <?php |
||
80 | class Async extends Component |
||
81 | { |
||
82 | |||
83 | /** |
||
84 | * @event SuccessEvent an event that is triggered when task done. |
||
85 | */ |
||
86 | const EVENT_SUCCESS = 'success'; |
||
87 | |||
88 | /** |
||
89 | * @event ErrorEvent an event that is triggered when task error. |
||
90 | */ |
||
91 | const EVENT_ERROR = 'error'; |
||
92 | |||
93 | /** |
||
94 | * @event \yii\base\Event an event that is triggered when task timeout. |
||
95 | */ |
||
96 | const EVENT_TIMEOUT = 'timeout'; |
||
97 | |||
98 | /** |
||
99 | * @var Pool handling tasks. |
||
100 | */ |
||
101 | protected $pool; |
||
102 | |||
103 | /** |
||
104 | * @var string a file config of an application run in child process. |
||
105 | * Note: If an autoload file's set, it will not affect, you need to invoke an app in your autoload if needed. |
||
106 | */ |
||
107 | protected $appConfigFile; |
||
108 | |||
109 | /** |
||
110 | * Async constructor. |
||
111 | * |
||
112 | * @param array $config |
||
113 | * @throws \yii\base\InvalidConfigException |
||
114 | */ |
||
115 | 8 | public function __construct($config = []) |
|
122 | |||
123 | /** |
||
124 | * Execute async task. |
||
125 | * |
||
126 | * @param callable|\Spatie\Async\Task|Task $callable need to execute. |
||
127 | * @param array $callbacks event. Have key is an event name, value is a callable triggered when event happen, |
||
128 | * have three events `error`, `success`, `timeout`. |
||
129 | * @return static |
||
130 | */ |
||
131 | 8 | public function run($callable, array $callbacks = []): self |
|
140 | |||
141 | /** |
||
142 | * This method is called when task executed success. |
||
143 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
144 | * event is triggered. |
||
145 | * |
||
146 | * @param mixed $output of task executed. |
||
147 | * @throws \yii\base\InvalidConfigException |
||
148 | */ |
||
149 | 3 | public function success($output): void |
|
158 | |||
159 | /** |
||
160 | * This method is called when task executed error. |
||
161 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
162 | * event is triggered. |
||
163 | * |
||
164 | * @param Throwable $throwable when executing task. |
||
165 | * @throws \yii\base\InvalidConfigException |
||
166 | */ |
||
167 | 1 | public function error(Throwable $throwable): void |
|
176 | |||
177 | /** |
||
178 | * This method is called when task executed timeout. |
||
179 | * When overriding this method, make sure you call the parent implementation to ensure the |
||
180 | * event is triggered. |
||
181 | * |
||
182 | * @throws \yii\base\InvalidConfigException |
||
183 | */ |
||
184 | 2 | public function timeout(): void |
|
190 | |||
191 | /** |
||
192 | * Register events to process given. |
||
193 | * |
||
194 | * @param array $events register to process given. |
||
195 | * @param Runnable $process need to add events. |
||
196 | * @since 1.0.3 |
||
197 | */ |
||
198 | 8 | protected function registerProcessEvents(array $events, Runnable $process): void |
|
217 | |||
218 | /** |
||
219 | * Register global events to process given. |
||
220 | * |
||
221 | * @param Runnable $process need to add global events. |
||
222 | */ |
||
223 | 8 | protected function registerProcessGlobalEvents(Runnable $process): void |
|
229 | |||
230 | /** |
||
231 | * Wait until all tasks done. |
||
232 | * |
||
233 | * @since 1.0.3 return results of async processes. |
||
234 | */ |
||
235 | 7 | public function wait() |
|
242 | |||
243 | /** |
||
244 | * Set concurrency process do tasks. |
||
245 | * |
||
246 | * @param int $concurrency |
||
247 | */ |
||
248 | public function setConcurrency(int $concurrency): void |
||
252 | |||
253 | /** |
||
254 | * Set timeout of task when execute. |
||
255 | * |
||
256 | * @param int $timeout |
||
257 | */ |
||
258 | 8 | public function setTimeout(int $timeout): void |
|
262 | |||
263 | /** |
||
264 | * Set sleep time when wait tasks execute. |
||
265 | * |
||
266 | * @param int $sleepTimeWait |
||
267 | */ |
||
268 | public function setSleepTimeWait(int $sleepTimeWait): void |
||
272 | |||
273 | /** |
||
274 | * Set autoload for environment tasks execute. |
||
275 | * @param string $autoload it can use at an alias. |
||
276 | */ |
||
277 | public function setAutoload(string $autoload): void |
||
281 | |||
282 | /** |
||
283 | * Set an application config file for invoke in child runtime process. |
||
284 | * |
||
285 | * @param string $appConfigFile it can use at an alias. |
||
286 | */ |
||
287 | 8 | public function setAppConfigFile(string $appConfigFile): void |
|
291 | |||
292 | /** |
||
293 | * Create an async process. |
||
294 | * |
||
295 | * @param callable|\Spatie\Async\Task|Task $callable need to execute. |
||
296 | * @return Runnable process. |
||
297 | */ |
||
298 | 8 | protected function createProcess($callable): Runnable |
|
302 | |||
303 | } |
||
304 |
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: