Files
XCSDD/docs/api/threading/task-group/waitfor.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +08:00

40 lines
860 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TaskGroup::WaitFor
```cpp
bool WaitFor(std::chrono::milliseconds timeout)
```
等待任务组中所有任务完成,可在超时后返回。
**参数:**
- `timeout` - 最大等待时间
**返回:** `bool` - 所有任务在超时前完成返回 true超时返回 false
**复杂度:** O(n)
**示例:**
```cpp
TaskGroup* group = TaskSystem::Get().CreateTaskGroup();
for (int i = 0; i < 5; ++i) {
group->AddTask([i]() {
Thread::Sleep(i * 100);
printf("Task %d done\n", i);
});
}
if (group->WaitFor(std::chrono::seconds(1))) {
printf("All tasks completed within 1 second\n");
} else {
printf("Timeout! Some tasks still running\n");
printf("Progress: %.1f%%\n", group->GetProgress() * 100.0f);
}
```
## 相关文档
- [TaskGroup 总览](task-group.md) - 返回类总览
- [Wait](wait.md) - 无超时等待