# wait()

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

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

运行到到达您命名的状态之一时, 运行将一直持续到运行。 默认情况下, 包括等待 —— 因为人类的运行停止后, 运行不会继续运行 。

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

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `until` | string[] | ["waiting", "succeeded", "failed", "cancelled"] | 哪个状态结束等待。 |
| `timeoutMs` | integer | 600 000 | 十分钟过去 `timeout` 扔了408个。 |
| `intervalMs` | integer | 2 000 | 读了多少次 |

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

## 为什么等待是在默认时间 {#waiting}

> **人类一步一步 等待无休无止**
>
> 默认的等待将最终总是在批准后超时任何工作流程中结束,而超时看起来将是一个失败。 将“停止某人入境”视为“抵达”是导致默认违约有用的原因。

## 等待最后 {#terminal}

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

合理时,当有其他事情批准人的步骤。 提高上限, 链条只要得到人的认可, 就可以持续多久。

## 超时不会停止运行 {#timeout}

扔着 `timeout` 继续跑 接住 晚点再来 [raun()](/zh/sdk/ref/workflows/get-run) -或打电话 [(取消)](/zh/sdk/ref/workflow-run/cancel) 如果你是想阻止的话

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

每个滴子都是读取,读取成本不高。 较短的间隔反应更快, 要求更多, 选择的平衡为两秒。

- [resume()](/zh/sdk/ref/workflow-run/resume): 通常接下来的是什么。
- [人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人 人](/zh/sdk/workflows/steps/human): 一步,使运行等待。

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