All wait functions must be called from inside a
task.run() block. They will throw if called
outside one.wait.for()
Pause execution for a fixed duration. Supported units: seconds, minutes, hours, days, weeks, months, years.
/trigger/wait-for-example.ts
Waits of 5 seconds or less count towards compute usage because the task does not checkpoint — it
stays resident in memory.
Idempotency
UseidempotencyKey to ensure a wait is only registered once if the task retries:
wait.until()
Pause execution until a specific Date:
/trigger/wait-until-example.ts
throwIfInThePast: true to throw an error if the date has already passed:
wait.forToken()
Pause a run until an external event completes a token. This is useful for human-in-the-loop workflows, webhooks from third-party services, or any external approval step.
How it works
1
Create a token
Inside your task, create a waitpoint token. The token has a URL that can be called to complete it.
/trigger/approval-task.ts
2
Complete the token
From anywhere in your codebase — or via HTTP callback — complete the token with a result:Or POST JSON to the token URL directly (useful for webhooks):
Using wait.forToken() with webhooks
This pattern is ideal for integrating with services that support webhooks:
/trigger/replicate-task.ts
Managing tokens
Lifecycle hooks during waits
UseonWait and onResume hooks to run code when a task pauses or resumes. This is useful for managing resources like database connections:
/trigger/db-task.ts