Skip to content

Commit edc664a

Browse files
committed
add withAfter
1 parent c6be740 commit edc664a

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

packages/workflow.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,36 @@ While `response()` creates implicit dependencies, use `withDepends()` for explic
662662

663663
```php
664664
$workflow = workflow(
665-
setup: async(SetupAction::class),
666-
process: async(
667-
ProcessAction::class,
668-
data: variable('input')
669-
)->withDepends('setup') // Wait for setup even without using its response
665+
exists: sync(ExistsAction::class),
666+
update: sync(UpdateAction::class)
667+
->withRunIf(response('exists')),
668+
cleanup: sync(CleanupAction::class)
669+
->withDepends('update')
670670
);
671671
```
672672

673+
For the code above, `cleanup` happens only if `update` runs and completes successfully. If `update` is skipped (because `exists` is false), then `cleanup` is also skipped since it depends on `update`.
674+
675+
---
676+
677+
## Run After Job
678+
679+
Use `withAfter()` to enforce ordering between jobs without creating a dependency. It guarantees that the target job is scheduled only after the specified job node has resolved.
680+
681+
```php
682+
$workflow = workflow(
683+
exists: sync(ExistsAction::class),
684+
update: sync(UpdateAction::class)
685+
->withRunIf(response('exists')),
686+
cleanup: sync(CleanupAction::class)
687+
->withAfter('update')
688+
);
689+
```
690+
691+
For the code above, `cleanup` happens after node `update` regardless of whether `update` actually ran or was skipped.
692+
693+
Without `withAfter('update')`, `cleanup` and `update` are independent and may run in any order (for example, `cleanup` could run before `update`). Adding `withAfter('update')` ensures `cleanup` is scheduled only after the `update` node resolves.
694+
673695
---
674696

675697
## Retry Policy

0 commit comments

Comments
 (0)