1 #include "rxcpp/rx.hpp" 2 3 #include "rxcpp/rx-test.hpp" 4 #include "catch.hpp" 5 6 SCENARIO("repeat sample"){ 7 printf("//! [repeat sample]\n"); 8 auto values = rxcpp::observable<>::from(1, 2). 9 repeat(). 10 take(5); 11 values. 12 subscribe( __anon7cfa98e90102(int v)13 [](int v){printf("OnNext: %d\n", v);}, __anon7cfa98e90202()14 [](){printf("OnCompleted\n");}); 15 printf("//! [repeat sample]\n"); 16 } 17 18 SCENARIO("repeat count sample"){ 19 printf("//! [repeat count sample]\n"); 20 auto values = rxcpp::observable<>::from(1, 2).repeat(3); 21 values. 22 subscribe( __anon7cfa98e90302(int v)23 [](int v){printf("OnNext: %d\n", v);}, __anon7cfa98e90402()24 [](){printf("OnCompleted\n");}); 25 printf("//! [repeat count sample]\n"); 26 } 27 28 SCENARIO("repeat error sample"){ 29 printf("//! [repeat error sample]\n"); 30 auto values = rxcpp::observable<>::from(1, 2). 31 concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). 32 repeat(); 33 values. 34 subscribe( __anon7cfa98e90502(int v)35 [](int v){printf("OnNext: %d\n", v);}, __anon7cfa98e90602(std::exception_ptr ep)36 [](std::exception_ptr ep){ 37 try {std::rethrow_exception(ep);} 38 catch (const std::exception& ex) { 39 printf("OnError: %s\n", ex.what()); 40 } 41 }, __anon7cfa98e90702()42 [](){printf("OnCompleted\n");}); 43 printf("//! [repeat error sample]\n"); 44 } 45