1 |
|
---|
2 | #define BOOST_THREAD_PROVIDES_FUTURE
|
---|
3 | #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
|
---|
4 |
|
---|
5 | #include <boost/thread/future.hpp>
|
---|
6 |
|
---|
7 | int main(int argc, char const *argv[])
|
---|
8 | {
|
---|
9 | boost::promise<int> prom;
|
---|
10 | boost::future<int> futr = prom.get_future();
|
---|
11 |
|
---|
12 | int callCount = 0;
|
---|
13 |
|
---|
14 | auto futr2 = futr.then(boost::launch::deferred,
|
---|
15 | [&] (boost::future<int> f) {
|
---|
16 | callCount++;
|
---|
17 | assert(f.valid());
|
---|
18 | assert(f.is_ready());
|
---|
19 | if (f.is_ready()) {
|
---|
20 | assert(17 == f.get());
|
---|
21 | }
|
---|
22 | });
|
---|
23 |
|
---|
24 | assert(futr2.valid());
|
---|
25 | assert(!futr2.is_ready());
|
---|
26 | assert(0 == callCount);
|
---|
27 |
|
---|
28 | prom.set_value(17);
|
---|
29 | assert(1 == callCount);
|
---|
30 |
|
---|
31 | futr2.get();
|
---|
32 | assert(1 == callCount);
|
---|
33 |
|
---|
34 | futr2.get();
|
---|
35 | assert(1 == callCount);
|
---|
36 | /* code */
|
---|
37 | return 0;
|
---|
38 | }
|
---|