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

860 B
Raw Blame History

TaskGroup::WaitFor

bool WaitFor(std::chrono::milliseconds timeout)

等待任务组中所有任务完成,可在超时后返回。

参数:

  • timeout - 最大等待时间

返回: bool - 所有任务在超时前完成返回 true超时返回 false

复杂度: O(n)

示例:

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

相关文档