switon / executor
Runner execution with batch, any-first, and task-scoped concurrency APIs for Switon Framework
v1.0.0
2026-06-07 03:31 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
- switon/event: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
Suggests
- ext-swoole: Coroutine paths; local/CI with ext runs full suite; without ext PHPUnit skips those classes (see CI matrix).
README
Switon's execution layer for container-registered runners, ordered batch results, first-success selection, and runner lifecycle events.
Highlights
- Task routing: task ids resolve to the right runner service.
- Batch execution:
invokeAll()keeps results in input order. - First-success mode:
invokeAny()returns the first successful result. - Lifecycle visibility:
RunnerStartingandRunnerFinishedexpose run data. - Async coordination:
FutureandGatesupport ordered task handling.
Installation
composer require switon/executor
Quick Start
use Switon\Core\Attribute\Autowired; use Switon\Core\RunnerInterface; use Switon\Executor\ExecutorInterface; use Switon\Executor\FutureInterface; final class ReportRunner implements RunnerInterface { public function run(mixed $payload): array { return ['id' => $payload['id']]; } } final class ReportService { #[Autowired] protected ExecutorInterface $executor; public function export(): array { $futures = $this->executor->invokeAll([ ['report:daily', ['id' => 1]], ['report:weekly', ['id' => 2]], ]); return array_map(static fn (FutureInterface $future) => $future->result(), $futures); } public function fallback(): mixed { return $this->executor->invokeAny([ ['report:primary', ['id' => 1]], ['report:backup', ['id' => 1]], ]); } }
Docs: https://docs.switon.dev/latest/executor
License
MIT.