> ## Documentation index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Search it with GET https://upstash.com/docs/search?q=<query>.
> Use these to discover all available pages before exploring further.

# Wait

You can pause a workflow run with the `waitForEvent` step. An event is uniquely identified by event ID.

The workflow will resume when the matching event is published.

`waitForEvent` supports configurable timeouts to prevent workflows from waiting indefinitely.
When a timeout occurs, the returned object includes `timeout: true`, allowing you to handle the failure case gracefully (for example, cancel an order, notify the user, or retry later).

<Tip>
If no timeout is specified, the default is **7 days**.
</Tip>

<CodeGroup>
```typescript TypeScript
import { serve } from "@upstash/workflow/nextjs";

export const { POST } = serve<string>(async (context) => {
  const { orderId, userEmail } = context.requestPayload;

  // Wait for order processing completion
  const { eventData, timeout } = await context.waitForEvent(
    "wait-for-order-processing",
    `order-${orderId}`,
    {
      timeout: "1d" // 1 day timeout
    }
  );

  if (timeout) {
    // Handle timeout scenario
    await context.run("handle-timeout", async () => {
      return await handleOrderTimeout(orderId, userEmail);
    });
    return;
  }

});
```

</CodeGroup>
