# wait()

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

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

Sondaggios fino che la runa raggiunge uno dei status che ha nominato. Per default, che include la espera — porque una runa parada per un humano non è una runa ancora funzionante.

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

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `until` | string[] | ["waiting", "succeeded", "failed", "cancelled"] | Quali status termina la espera. |
| `timeoutMs` | integer | 600 000 | Dieci minuti. Passato, `timeout` (408) è lançat. |
| `intervalMs` | integer | 2 000 | Quante frequent i re-leads. |

```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
}
```

## Por qu'esperare è in predefinit {#waiting}

> **Un passo umano attende indefinitamente**
>
> Senza attendere in lista, l'attesa predefinita finirebbe sempre in un tempo di tempo di workflow con un'approvazione — e il tempo di tempo di pare un fallimento. Trattare « fermato per una persona » come un arrivo è lo che rende il default utile.

## Attesa solo per il fin {#terminal}

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

Ragionable quando qualcos'altro approva i passi umani. Levanta il tetto con il — una catena con una aprovação in esso può durar tanto quanto una persona toma.

## Il tempo di stop non ferma la fuga {#timeout}

Se lance `timeout` (408) e la run continua. Attrapalo e reviendra tarda con [getRun()](/pt/sdk/ref/workflows/get-run) — o chiama [cancel()](/pt/sdk/ref/workflow-run/cancel) se tu volès fermar.

```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;
}
```

## Il pollere è liber, ma non instant {#polling-cost}

Cada tick è un let e let nul costo. Un intervale corto reagisce più veloce e fa più richieste — due secondi è il saldo ellegit.

- [resume()](/pt/sdk/ref/workflow-run/resume): - Quello che normalmente segue.
- [humanos](/pt/sdk/workflows/steps/human): Il pas che fa un attesa di run.

```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.
```
