• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <rxcpp/rx-lite.hpp>
3 #include <rxcpp/operators/rx-take.hpp>
4 
5 #include <rxcpp/rx-coroutine.hpp>
6 
7 using namespace rxcpp;
8 using namespace rxcpp::sources;
9 using namespace rxcpp::operators;
10 using namespace rxcpp::util;
11 
12 using namespace std;
13 using namespace std::chrono;
14 
intervals()15 future<void> intervals(){
16 
17     {
18         printf("early exit from interval on thread\n");
19         for co_await (auto c : interval(seconds(1), observe_on_event_loop())) {
20             printf("%d\n", c);
21             break;
22         }
23     }
24 
25     {
26         printf("interval on thread\n");
27         for co_await (auto c : interval(seconds(1), observe_on_event_loop()) | take(3)) {
28             printf("%d\n", c);
29         }
30     }
31 
32     {
33         printf("current thread\n");
34         int last = 0;
35         for co_await (auto c : range(1, 100000)) {
36             last = c;
37         }
38         printf("reached %d\n", last);
39     }
40 
41     try {
42         printf("error in observable\n");
43         for co_await (auto c : error<long>(runtime_error("stopped by error"))) {
44             printf("%d\n", c);
45         }
46         printf("not reachable\n");
47         terminate();
48     }
49     catch(const exception& e) {
50         printf("%s\n", e.what());
51     }
52 }
53 
main()54 int main()
55 {
56     intervals().get();
57     return 0;
58 }
59