forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemplace.cpp
37 lines (27 loc) · 926 Bytes
/
emplace.cpp
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
// This example shows how to create task using either 'emplace'
// or 'silent_emplace'.
#include <cassert>
#include <taskflow/taskflow.hpp>
int main(){
tf::Taskflow tf;
// The method emplace gives you a future to retrieve the result.
// You may pass this future to another thread or program context
// to enable more asynchronous control flows.
auto [A, fuA] = tf.emplace([] () {
std::cout << "Task A\n";
return 1;
});
A.name("A");
// The method silent_emplace won't give you a future.
// Therefore, you won't be able to get the return value of the callable.
// Typically, silent_emplace is used for callables with no return values.
auto B = tf.silent_emplace([] () {
std::cout << "Task B\n";
return "no one can get me";
});
B.name("B");
// The future of A won't be ready until you execute the taskflow.
tf.wait_for_all();
assert(fuA.get() == 1);
return 0;
}