-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpromfut.cpp
More file actions
58 lines (46 loc) · 1.14 KB
/
promfut.cpp
File metadata and controls
58 lines (46 loc) · 1.14 KB
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
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <future>
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <iostream>
#include <chrono>
using namespace std::literals::chrono_literals;
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "study.hpp"
using namespace boost::asio;
using namespace std;
using ip::udp;
struct banger {
boost::asio::io_service serv;
boost::asio::deadline_timer dt;
boost::asio::io_service::work work;
std::promise<int> prom;
banger(int howlong) :dt(serv, boost::posix_time::seconds(howlong)), work(serv) { }
std::future<int> doit()
{
BARK();
auto cb = [&](const boost::system::error_code&) {
std::cout << "CB!\n";
prom.set_value(13);
};
dt.async_wait(cb);
return prom.get_future();
}
};
int main()
{
banger b(1);
std::thread runner([&b]() { b.serv.run(); });
BARK();
std::future<int> fi = b.doit();
std::this_thread::sleep_for(2s);
std::cout << "ready to read...\n";
std::cout << "reading int from future = " << fi.get() << "\n";
runner.join();
return 0;
}