Skip to main content
Waiting allows you to write complex tasks as straightforward async code. A waiting task releases its compute slot and only resumes when ready — you are not charged for idle time above 5 seconds.
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

Use idempotencyKey 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
Pass 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

Use onWait 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