switon/executor

Runner execution with batch, any-first, and task-scoped concurrency APIs for Switon Framework

Maintainers

Package info

github.com/switon-php/executor

Documentation

pkg:composer/switon/executor

Statistics

Installs: 13

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-07 03:31 UTC

This package is auto-updated.

Last update: 2026-06-07 03:36:15 UTC


README

Executor CI PHP 8.3+

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: RunnerStarting and RunnerFinished expose run data.
  • Async coordination: Future and Gate support 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.