• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "rxcpp/rx.hpp"
2 
3 #include "rxcpp/rx-test.hpp"
4 #include "catch.hpp"
5 
6 SCENARIO("delay period+coordination sample"){
7     printf("//! [delay period+coordination sample]\n");
8     using namespace std::chrono;
9     auto scheduler = rxcpp::identity_current_thread();
10     auto start = scheduler.now();
11     auto period = milliseconds(10);
__anon9cdd0dfe0102(const char* s) 12     const auto next = [=](const char* s) {
13         return [=](long v){
14             auto t = duration_cast<milliseconds>(scheduler.now() - start);
15             long long int ms = t.count();
16             printf("[%s @ %lld] OnNext: %ld\n", s, ms, v);
17         };
18     };
19     auto values = rxcpp::observable<>::interval(start, period, scheduler).
20         take(4).
21         tap(next("interval")).
22         delay(period, rxcpp::observe_on_new_thread());
23     values.
24         as_blocking().
25         subscribe(
26             next(" delayed"),
__anon9cdd0dfe0302()27             [](){printf("OnCompleted\n");});
28     printf("//! [delay period+coordination sample]\n");
29 }
30 
31 SCENARIO("delay period sample"){
32     printf("//! [delay period sample]\n");
33     using namespace std::chrono;
34     auto scheduler = rxcpp::identity_current_thread();
35     auto start = scheduler.now();
36     auto period = milliseconds(10);
__anon9cdd0dfe0402(const char* s) 37     const auto next = [=](const char* s) {
38         return [=](long v){
39             auto t = duration_cast<milliseconds>(scheduler.now() - start);
40             long long int ms = t.count();
41             printf("[%s @ %lld] OnNext: %ld\n", s, ms, v);
42         };
43     };
44     auto values = rxcpp::observable<>::interval(start, period, scheduler).
45         take(4).
46         tap(next("interval")).
47         delay(period);
48     values.
49         subscribe(
50             next(" delayed"),
__anon9cdd0dfe0602()51             [](){printf("OnCompleted\n");});
52     printf("//! [delay period sample]\n");
53 }
54