blob: 9cd8d43f2fd78d38b5426bd4205ee08bf544a199 (
plain)
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
36
37
38
39
40
41
42
43
44
|
#include "rxcpp/rx.hpp"
#include "rxcpp/rx-test.hpp"
#include "catch.hpp"
SCENARIO("repeat sample"){
printf("//! [repeat sample]\n");
auto values = rxcpp::observable<>::from(1, 2).
repeat().
take(5);
values.
subscribe(
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
printf("//! [repeat sample]\n");
}
SCENARIO("repeat count sample"){
printf("//! [repeat count sample]\n");
auto values = rxcpp::observable<>::from(1, 2).repeat(3);
values.
subscribe(
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
printf("//! [repeat count sample]\n");
}
SCENARIO("repeat error sample"){
printf("//! [repeat error sample]\n");
auto values = rxcpp::observable<>::from(1, 2).
concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))).
repeat();
values.
subscribe(
[](int v){printf("OnNext: %d\n", v);},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){printf("OnCompleted\n");});
printf("//! [repeat error sample]\n");
}
|