Files
XCEngine/docs/api/XCEngine/Threading/TaskGroup/WaitFor.md

32 lines
743 B
Markdown
Raw Normal View History

2026-03-26 16:45:24 +08:00
# TaskGroup::WaitFor
2026-03-26 20:59:59 +08:00
在给定超时时间内等待任务组完成。
2026-03-26 16:45:24 +08:00
```cpp
bool WaitFor(std::chrono::milliseconds timeout);
```
2026-03-26 20:59:59 +08:00
## 行为说明
2026-03-26 16:45:24 +08:00
2026-03-26 20:59:59 +08:00
当前实现使用 `condition_variable::wait_for`,等待谓词 `m_pendingCount.load() == 0`
2026-03-26 16:45:24 +08:00
2026-03-26 20:59:59 +08:00
## 参数
2026-03-26 16:45:24 +08:00
2026-03-26 20:59:59 +08:00
- `timeout` - 最长等待时间。
2026-03-26 16:45:24 +08:00
2026-03-26 20:59:59 +08:00
## 返回值
2026-03-26 16:45:24 +08:00
2026-03-26 20:59:59 +08:00
- 若谓词在超时前成立则返回 `true`
- 否则返回 `false`
## 当前实现限制
- 与 [Wait](Wait.md) 一样,当前 `m_pendingCount` 只增不减,因此非空任务组几乎总会超时返回 `false`
- [Cancel](Cancel.md) 不会通知等待者,所以取消也不会帮助 `WaitFor()` 提前结束。
2026-03-26 16:45:24 +08:00
## 相关文档
2026-03-26 20:59:59 +08:00
- [返回类型总览](TaskGroup.md)
- [Wait](Wait.md)
- [GetProgress](GetProgress.md)