#is there any way to create an artificial delay in a query or mutation?

3 messages · Page 1 of 1 (latest)

spark owl
#

is there any way to create an artificial delay in a query or mutation?

twin lanternBOT
#

Hi @spark owl. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

There is no explicit mention in the knowledge sources of a built-in Convex API for introducing an artificial delay (such as sleep or wait) directly inside a query or mutation. However, in the context of data migration scripts or actions running outside Convex (e.g., in Node.js), you can use standard JavaScript techniques like setTimeout or await new Promise(resolve => setTimeout(resolve, ms)) to introduce delays between operations, as shown in a migration script example:

await new Promise(resolve => setTimeout(resolve, 100)); // 100ms delay

But this is outside the Convex function runtime, not inside a Convex query or mutation itself MongoDB to Convex: A Step-by-Step Data Migration Script.

Within Convex queries and mutations, there is no documented or recommended way to introduce artificial delays, and doing so would generally be discouraged as it could block the transactional execution model and impact performance.

If you need to schedule work to happen later, Convex provides scheduled functions via ctx.scheduler, but this is for deferring execution, not for pausing within a function Scheduled Functions.

In summary:

  • Artificial delays inside Convex queries/mutations are not documented or recommended.
  • Delays can be introduced in external scripts or clients, but not within Convex function bodies themselves.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: