-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventual-4.cc
35 lines (30 loc) · 906 Bytes
/
eventual-4.cc
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
#include <string>
#include "eventuals/eventual.h"
#include "eventuals/promisify.h"
#include "eventuals/raise.h"
using namespace eventuals;
int main(int argc, char** argv) {
auto e = []() {
return Eventual<std::string>()
.context("never slept!")
.start([](auto& context, auto& k) {
auto thread = std::thread(
[&k]() mutable {
sleep(2);
k.Start("awake!");
});
thread.detach();
std::cout << "thread will sleep for 2 seconds ..." << std::endl;
})
.fail([](auto& context, auto& k, auto&& e) {
// "Catch" raised error.
CHECK_STREQ("error!", e.what());
k.Start(context);
})
.stop([](auto& context, auto& k) {
k.Stop(); // Propagate stop.
});
};
CHECK_EQ("never slept!", *(Raise("error!") >> e()));
return 0;
}