# wait()

Canonical URL: https://developers.iagenify.com/sdk/ref/workflow-run/wait/
Language: en

`run.wait({ until?, timeoutMs?, intervalMs? }) → Promise<WorkflowRun>`

Polls until the run reaches one of the statuses you named. By default that includes waiting — because a run stopped for a human is not a run still working.

Status: 10 minutes · every 2 seconds · waiting counts as arrived

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `until` | string[] | ["waiting", "succeeded", "failed", "cancelled"] | Which statuses end the wait. |
| `timeoutMs` | integer | 600 000 | Ten minutes. Past it, `timeout` (408) is thrown. |
| `intervalMs` | integer | 2 000 | How often it re-reads. |

```javascript
await run.wait();

if (run.data.status === "waiting") {
  const step = run.data.steps.find((s) => s.status === "waiting");
  await run.resume(step.id, { approved: true });
  await run.wait();                       // then on to the end
}
```

## Why waiting is in the default {#waiting}

> **A human step waits indefinitely**
>
> Without waiting in the list, the default wait would always end in a timeout on any workflow with an approval — and the timeout would look like a failure. Treating « stopped for a person » as an arrival is what makes the default useful.

## Waiting only for the end {#terminal}

```javascript
await run.wait({ until: ["succeeded", "failed", "cancelled"], timeoutMs: 30 * 60_000 });
```

Reasonable when something else approves the human steps. Raise the ceiling with it — a chain with an approval in it can take as long as a person takes.

## The timeout does not stop the run {#timeout}

It throws `timeout` (408) and the run keeps going. Catch it and come back later with [getRun()](/sdk/ref/workflows/get-run) — or call [cancel()](/sdk/ref/workflow-run/cancel) if you meant to stop it.

```javascript
import { IaGenifyError } from "iagenify";

try {
  await run.wait({ timeoutMs: 60_000 });
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "timeout") {
    // Still running. Keep run.id and come back.
  } else throw err;
}
```

## Polling is free, but not instant {#polling-cost}

Each tick is a read and reads cost nothing. A shorter interval reacts faster and makes more requests — two seconds is the balance chosen.

- [resume()](/sdk/ref/workflow-run/resume): What usually follows.
- [human](/sdk/workflows/steps/human): The step that makes a run wait.

```python
run.wait()

if run.data["status"] == "waiting":
    step = next(s for s in run.data["steps"] if s["status"] == "waiting")
    run.resume(step["id"], {"approved": True})
    run.wait()                       # then on to the end
```

```python
run.wait(until=["succeeded", "failed", "cancelled"], timeout_ms=30 * 60_000)
```

```python
from iagenify import IaGenifyError

try:
    run.wait(timeout_ms=60_000)
except IaGenifyError as error:
    if error.code != "timeout":
        raise
    # Still running. Keep run.id and come back.
```
