Skip to content

Wait Functions

Wait functions pause task execution without consuming compute resources during the wait period.

Checkpoint-Resume

In Trigger.dev Cloud, waiting tasks are checkpointed — their state is saved and resources released. You are not charged for wait time.

wait.for()

Wait for a specific duration:

ts
import { task, wait } from "@trigger.dev/sdk";

export const myTask = task({
  id: "my-task",
  run: async (payload) => {
    await wait.for({ seconds: 30 });
    await wait.for({ minutes: 5 });
    await wait.for({ hours: 1 });
    await wait.for({ days: 1 });
    await wait.for({ weeks: 1 });
    await wait.for({ months: 1 });
  },
});

Waits longer than 5 seconds are checkpointed (no compute cost).

wait.until()

Wait until a specific date/time:

ts
await wait.until({ date: new Date("2025-12-31T23:59:59Z") });

// Dynamic date
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
await wait.until({ date: tomorrow });

wait.forToken()

Pause a run until a specific token is completed (human-in-the-loop):

ts
import { task, wait } from "@trigger.dev/sdk";

export const approvalTask = task({
  id: "approval-task",
  run: async (payload) => {
    const token = await wait.createToken({ timeout: "24h" });

    // Send approval link to user (e.g., via email)
    await sendApprovalEmail(payload.email, token.publicAccessToken);

    // Wait indefinitely (up to timeout) for token completion
    const result = await wait.forToken<{ approved: boolean }>(token);

    if (result.ok) {
      console.log("Approved:", result.output.approved);
    } else {
      console.log("Token expired or rejected");
    }
  },
});

Complete the token from your API:

ts
import { auth, runs } from "@trigger.dev/sdk";

// In your API route (e.g., when user clicks "Approve")
await runs.completeToken(tokenId, { approved: true });

Wait Function Comparison

FunctionUse When
wait.for()Waiting a fixed duration
wait.until()Waiting until a specific time
wait.forToken()Waiting for external approval or event
yourTask.triggerAndWait()Waiting for a subtask to complete
yourTask.batchTriggerAndWait()Waiting for multiple subtasks

Built from official Trigger.dev documentation