forked from rafzi/WAMP_POCO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_when_all.cpp
84 lines (65 loc) · 2.23 KB
/
test_when_all.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Copyright (C) 2014 Tavendo GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
#include <boost/thread/future.hpp>
using namespace boost;
using namespace std;
int main() {
future<int> f1 = async([]() { return 1; });
//future<int> f2 = async([]() { return 2; });
//future<int> f3 = async([]() { return 3; });
auto f1_ = f1.then([](decltype(f1) res) {
cout << "f1 done" << endl;
int ires = res.get();
auto fi = async([=]() { return 11 + ires; });
//return fi.get();
//return 11 + ires;
return async([=]() { return 11 + ires; });
});
int fres = f1_.get().get();
// int fres = f1_.unwrap().get();
// int fres = f1_.get();
cout << "fres done" << fres << endl;
/*
auto f1_d = f1_.then([](decltype(f1_)) {
std::cout << "f1_ done" << std::endl;
});
f1_d.get();
auto f2_ = f2.then([](decltype(f2) res) {
std::cout << "f2 done" << std::endl;
});
auto f3_ = f3.then([](decltype(f3) res) {
std::cout << "f3 done" << std::endl;
});
auto f12 = when_all(std::move(f1), std::move(f2));
auto f12d = f12.then([](decltype(f12)) {
std::cout << "f12 done" << std::endl;
});
auto f23 = when_all(std::move(f2), std::move(f3));
auto f23d = f23.then([](decltype(f23)) {
std::cout << "f23 done" << std::endl;
});
auto f123 = when_all(std::move(f12d), std::move(f23d));
auto fall = f123.then([](decltype(f123)) {
std::cout << "all done" << std::endl;
});
fall.get();
*/
}