From 46a1afddb4358fc759d00830399c8f5ca708aa11 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sun, 4 Nov 2018 18:03:14 +0100 Subject: [PATCH] Add custom task docs --- docs/custom-tasks.md | 80 ++++++++++++++++++++++++++++++++++++++++++++ docs/index.md | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/custom-tasks.md diff --git a/docs/custom-tasks.md b/docs/custom-tasks.md new file mode 100644 index 0000000..3edffe7 --- /dev/null +++ b/docs/custom-tasks.md @@ -0,0 +1,80 @@ +--- +title: Custom tasks +permalink: /custom-tasks +--- +Instead of passing simple callables to workers, this package also allows custom implementations of the `Task` interface to dispatch work in child processes or threads. + +## `Task` + +The `Task` interface has a single `run()` method that gets invoked in the worker to dispatch the work that needs to be done. + +```php + $response) { If you just want to fetch multiple HTTP resources concurrently, it's better to use [Artax](https://amphp.org/artax/), our non-blocking HTTP client. The functions you call must be predefined or autoloadable by Composer so they also exist in the worker processes. -Instead of simple callables, you can also enqueue `Task` instances with `Amp\Parallel\Worker\enqueue()`. \ No newline at end of file +Instead of simple callables, you can also [enqueue `Task` instances](./custom-tasks.md) with `Amp\Parallel\Worker\enqueue()`. \ No newline at end of file