Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: flow.exit updates #14498

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading