blob: 0dd97a5d4d84b5cc44969abf05b1e455699955ad (
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
45
46
47
48
49
50
51
52
53
|
#include "rxcpp/rx.hpp"
#include "rxcpp/rx-test.hpp"
#include "catch.hpp"
SCENARIO("delay period+coordination sample"){
printf("//! [delay period+coordination sample]\n");
using namespace std::chrono;
auto scheduler = rxcpp::identity_current_thread();
auto start = scheduler.now();
auto period = milliseconds(10);
const auto next = [=](const char* s) {
return [=](long v){
auto t = duration_cast<milliseconds>(scheduler.now() - start);
long long int ms = t.count();
printf("[%s @ %lld] OnNext: %ld\n", s, ms, v);
};
};
auto values = rxcpp::observable<>::interval(start, period, scheduler).
take(4).
tap(next("interval")).
delay(period, rxcpp::observe_on_new_thread());
values.
as_blocking().
subscribe(
next(" delayed"),
[](){printf("OnCompleted\n");});
printf("//! [delay period+coordination sample]\n");
}
SCENARIO("delay period sample"){
printf("//! [delay period sample]\n");
using namespace std::chrono;
auto scheduler = rxcpp::identity_current_thread();
auto start = scheduler.now();
auto period = milliseconds(10);
const auto next = [=](const char* s) {
return [=](long v){
auto t = duration_cast<milliseconds>(scheduler.now() - start);
long long int ms = t.count();
printf("[%s @ %lld] OnNext: %ld\n", s, ms, v);
};
};
auto values = rxcpp::observable<>::interval(start, period, scheduler).
take(4).
tap(next("interval")).
delay(period);
values.
subscribe(
next(" delayed"),
[](){printf("OnCompleted\n");});
printf("//! [delay period sample]\n");
}
|