Skip to content

Commit

Permalink
Add coroutine support docs for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
babarinde committed Jul 14, 2020
1 parent c321b39 commit fc0aceb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/book/v2/async-tasks.md
Expand Up @@ -26,12 +26,14 @@ no concurrency and tasks will execute one after the other.

```php
'mezzio-swoole' => [
'enable_coroutine' => true, //optional to enable coroutines and useful for tasks coroutines
'swoole-http-server' => [
'host' => '127.0.0.1',
'port' => 8080,
'options' => [
'worker_num' => 4, // The number of HTTP Server Workers
'task_worker_num' => 4, // The number of Task Workers
'task_enable_coroutine' => true, // optional to turn on task coroutine support
],
],
];
Expand Down Expand Up @@ -78,6 +80,25 @@ where:
when initially triggering the task. This value can be any PHP value, with the
exception of a `resource`.

If coroutine support is enabled for tasks, the signature for the `task` event handler is:

```php
function (
\Swoole\Http\Server $server,
\Swoole\Server\Task $task
) : void
```
where:

- `$server` is the main HTTP server process
- `$task->id` is a number that increments each time the server triggers a new task.
- `$task->worker_id` is an integer that defines the worker process that is
executing the workload.
- `$task->data` contains the value passed to the `$server->task()` method
when initially triggering the task. This value can be any PHP value, with the
exception of a `resource`.
- `$task->flag` is the type of task

To register the handler with the server, you must call it's `on()` method,
**before** the server has been started:

Expand Down

0 comments on commit fc0aceb

Please sign in to comment.