-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathtask_group.h
49 lines (40 loc) · 917 Bytes
/
task_group.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
namespace cswinrt
{
struct task_group
{
task_group(task_group const&) = delete;
task_group& operator=(task_group const&) = delete;
task_group() noexcept = default;
~task_group() noexcept
{
for (auto&& task : m_tasks)
{
task.wait();
}
}
template <typename T>
void add(T&& callback)
{
#if defined(_DEBUG)
callback();
#else
m_tasks.push_back(std::async(std::forward<T>(callback)));
#endif
}
void get()
{
auto tasks = std::move(m_tasks);
for (auto&& task : tasks)
{
task.wait();
}
for (auto&& task : tasks)
{
task.get();
}
}
private:
std::vector<std::future<void>> m_tasks;
};
}