Clarity on code executed outside of steps #586
-
Hello, I'm reading the documentation on Multi-Step Functions, and wanted to make sure I understand how the code run outside of steps is invoked. Take the following Inngest function: export type InngestUpdateUserEvent = {
data: { userId: string }
}
const inngestUpdateUser = inngest.createFunction(
{ name: 'User > Update' },
{ event: 'user.update' },
async ({ event, step }) => {
const user = await getUser(event.data.userId)
await step.run('Update user name', async () => {
await saveUser({ ...user, name: 'New Name' })
})
await step.run('Email user', async () => {
await sendEmail(user, `Your name has been updated to ${user.name}`)
})
},
) Is |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It runs many times. Steps run once and the first run's output is stored in function state and injected on the next run. Code outside of steps is ran multiple times up until we execute the next step. For example, if this await was at the end of the function it only runs once, as it's not executed until all steps finish. However, being at the top it's ran every time a step is invoked. |
Beta Was this translation helpful? Give feedback.
It runs many times. Steps run once and the first run's output is stored in function state and injected on the next run.
Code outside of steps is ran multiple times up until we execute the next step. For example, if this await was at the end of the function it only runs once, as it's not executed until all steps finish. However, being at the top it's ran every time a step is invoked.