Skip to content

Commit

Permalink
docs: flow.exit updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha authored Nov 4, 2024
1 parent 50c1714 commit 165d7ce
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs-v2/pages/code/nodejs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,28 @@ Sometimes you want to end your workflow early, or otherwise stop or cancel the e
**In any code step, calling `return $.flow.exit()` will end the execution of the workflow immediately.** No remaining code in that step, and no code or destination steps below, will run for the current event.

<Callout type="info">
It's a good practice to use `return $.flow.exit()` to immediately exit the workflow.
In contrast, `$.flow.exit()` on its own will end the workflow only after executing all remaining code in the step.
`$.flow.exit()` does not exit the workflow immediately, only after all remaining code has been executed.
If you want to exit the workflow immediately, you need to use other control structures to do so.
It is best practice to return the value of `$.flow.exit()`.
</Callout>

```javascript
export default defineComponent({
async run({ steps, $ }) {
$.flow.exit();
console.log(
"This code will still run, the workflow is ended after"
);
},
});
```

```javascript
export default defineComponent({
async run({ steps, $ }) {
return $.flow.exit();
console.log(
"This code will not run, since $.flow.exit() was called above it"
"This code will not run, as we returned from the `run` function early"
);
},
});
Expand Down

0 comments on commit 165d7ce

Please sign in to comment.