Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit e0b9167

Browse files
authored
Merge pull request #215 from marscoo/support-task_enable_coroutine-option
Update Manager.php
2 parents 22c775e + 2922c4a commit e0b9167

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Server/Manager.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,19 @@ protected function resetOnRequest()
255255
* Set onTask listener.
256256
*
257257
* @param mixed $server
258-
* @param string $taskId
259-
* @param string $srcWorkerId
260-
* @param mixed $data
258+
* @param string|\Swoole\Server\Task $taskIdOrTask
259+
* @param string $srcWorkerId Optional
260+
* @param mixed $data Optional
261261
*/
262-
public function onTask($server, $taskId, $srcWorkerId, $data)
262+
public function onTask($server, ...$args)
263263
{
264-
$this->container->make('events')->fire('swoole.task', func_get_args());
264+
if ($args[0] instanceof \Swoole\Server\Task && $task = array_shift($args)) {
265+
list($taskId, $srcWorkerId, $data) = [$task->id, $task->worker_id, $task->data];
266+
} else {
267+
list($taskId, $srcWorkerId, $data) = $args;
268+
}
269+
270+
$this->container->make('events')->fire('swoole.task', [$server, $taskId, $srcWorkerId, $data]);
265271

266272
try {
267273
// push websocket message

0 commit comments

Comments
 (0)