#Are immediately scheduled functions FIFO?

6 messages · Page 1 of 1 (latest)

uneven falcon
#

i.e. if I write

export const doLotsOfThings = internalMutation({
  args: {},
  handler: async (ctx) => {
    const items = await ctx.db.query('items').collect()

    for (const item of items) {
      await ctx.scheduler.runAfter(0, internal.items.doSomethingToItem, {
        itemId: item._id,
      })
    }

    await ctx.scheduler.runAfter(0, internal.somethingElse.doSomeGlobalThing)
  },
})

is it guaranteed that all doSomethingToItem will have resolved before doSomeGlobalThing is called?

thorny ospreyBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

    - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
    - Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
    - Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
    - Avoid tagging staff unless specifically instructed.

    Thank you!
light panther
#

nope, they run with parallelism

uneven falcon
#

thanks! is there a way I can run a bunch of things, await them all to complete, then run something else?

#

if just using Promise.all or for/await in this function, I would hit the execution time limit

light panther
#

hmm sounds like a tricky problem. you can probably coordinate this by writing statuses to the database, and each one of the "bunch of things" at the end checks if all the others are done, and if they are, schedules the "something else"