Skip to main content
Creates a synchronous (blocking) job for the given action and arguments.

Signature

function sync(
    ActionInterface|string|callable $_,
    mixed ...$argument
): JobInterface

Parameters

$_
ActionInterface|class-string<ActionInterface>|callable
required
The action to run. Can be:
  • An ActionInterface instance
  • A class string of an Action class
  • Any PHP callable (closure, function, invokable object)
argument
mixed
Named arguments for the action’s run method. Values can be:
  • Literal values (strings, integers, arrays, etc.)
  • variable() references for runtime variables
  • response() references to previous job outputs

Returns

JobInterface
JobInterface
A synchronous job that will block execution until complete.

Usage

With a closure

use function Chevere\Workflow\{workflow, sync, variable};

$workflow = workflow(
    calculate: sync(
        function (int $a, int $b): int {
            return $a + $b;
        },
        a: 10,
        b: variable('value')
    )
);

With an Action class

use Chevere\Demo\Actions\Greet;
use function Chevere\Workflow\{workflow, sync, variable};

$workflow = workflow(
    greet: sync(
        new Greet(),
        username: variable('username')
    )
);

With a class string

use function Chevere\Workflow\{workflow, sync, variable};

$workflow = workflow(
    greet: sync(
        MyAction::class,
        foo: variable('super')
    )
);

Chaining jobs

use function Chevere\Workflow\{workflow, sync, variable, response};

$workflow = workflow(
    greet: sync(
        MyAction::class,
        foo: variable('super')
    ),
    capo: sync(
        MyAction::class,
        foo: response('greet')
    ),
    wea: sync(
        function (string $foo) {
            return "Wea, {$foo}";
        },
        foo: response('greet')
    )
);

Notes

  • Synchronous jobs block execution until they complete
  • Jobs run in sequence when they have dependencies
  • Use sync() for operations that must complete before other jobs can proceed
  • For non-blocking execution, use async() instead

Build docs developers (and LLMs) love