Home | History | Annotate | Download | only in doxygen
      1 #include "rxcpp/rx.hpp"
      2 
      3 #include "rxcpp/rx-test.hpp"
      4 #include "catch.hpp"
      5 
      6 SCENARIO("immediate interval sample"){
      7     printf("//! [immediate interval sample]\n");
      8     auto period = std::chrono::milliseconds(1);
      9     auto values = rxcpp::observable<>::interval(period);
     10     values.
     11         take(3).
     12         subscribe(
     13             [](int v){printf("OnNext: %d\n", v);},
     14             [](){printf("OnCompleted\n");});
     15     printf("//! [immediate interval sample]\n");
     16 }
     17 
     18 SCENARIO("threaded immediate interval sample"){
     19     printf("//! [threaded immediate interval sample]\n");
     20     auto scheduler = rxcpp::identity_current_thread();
     21     auto period = std::chrono::milliseconds(1);
     22     auto values = rxcpp::observable<>::interval(period, scheduler);
     23     values.
     24         take(3).
     25         subscribe(
     26             [](int v){printf("OnNext: %d\n", v);},
     27             [](){printf("OnCompleted\n");});
     28     printf("//! [threaded immediate interval sample]\n");
     29 }
     30 
     31 SCENARIO("interval sample"){
     32     printf("//! [interval sample]\n");
     33     auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
     34     auto period = std::chrono::milliseconds(1);
     35     auto values = rxcpp::observable<>::interval(start, period);
     36     values.
     37         take(3).
     38         subscribe(
     39             [](int v){printf("OnNext: %d\n", v);},
     40             [](){printf("OnCompleted\n");});
     41     printf("//! [interval sample]\n");
     42 }
     43 
     44 SCENARIO("threaded interval sample"){
     45     printf("//! [threaded interval sample]\n");
     46     auto scheduler = rxcpp::identity_current_thread();
     47     auto start = scheduler.now() + std::chrono::milliseconds(1);
     48     auto period = std::chrono::milliseconds(1);
     49     auto values = rxcpp::observable<>::interval(start, period, scheduler);
     50     values.
     51         take(3).
     52         subscribe(
     53             [](int v){printf("OnNext: %d\n", v);},
     54             [](){printf("OnCompleted\n");});
     55     printf("//! [threaded interval sample]\n");
     56 }
     57