RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
Classes | Namespaces | Macros | Functions
rx-buffer_time.hpp File Reference

Return an observable that emits buffers every period time interval and collects items from this observable for period of time into each produced buffer. If the skip parameter is set, Return an observable that emits buffers every skip time interval and collects items from this observable for period of time into each produced buffer, on the specified scheduler. More...

#include "../rx-includes.hpp"
Include dependency graph for rx-buffer_time.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rxcpp::member_overload< buffer_with_time_tag >
 

Namespaces

 rxcpp
 
 rxcpp::operators
 

Macros

#define RXCPP_OPERATORS_RX_BUFFER_WITH_TIME_HPP
 

Functions

template<class... AN>
auto rxcpp::operators::buffer_with_time (AN &&...an) -> operator_factory< buffer_with_time_tag, AN... >
 Return an observable that emits buffers every period time interval and collects items from this observable for period of time into each produced buffer. If the skip parameter is set, Return an observable that emits buffers every skip time interval and collects items from this observable for period of time into each produced buffer, on the specified scheduler. More...
 

Detailed Description

Return an observable that emits buffers every period time interval and collects items from this observable for period of time into each produced buffer. If the skip parameter is set, Return an observable that emits buffers every skip time interval and collects items from this observable for period of time into each produced buffer, on the specified scheduler.

Template Parameters
Durationthe type of the time interval
Coordinationthe type of the scheduler (optional).
Parameters
periodthe period of time each buffer collects items before it is emitted.
skipthe period of time after which a new buffer will be created (optional).
coordinationthe scheduler for the buffers (optional).
Returns
Observable that emits buffers every period time interval and collect items from this observable for period of time into each produced buffer. If the skip parameter is set, return an Observable that emits buffers every skip time interval and collect items from this observable for period of time into each produced buffer.
Sample Code
printf("[thread %s] Start task\n", get_pid().c_str());
auto period = std::chrono::milliseconds(4);
auto skip = std::chrono::milliseconds(6);
auto values = rxcpp::observable<>::interval(std::chrono::steady_clock::now() + std::chrono::milliseconds(1), std::chrono::milliseconds(2)).
map([](long v){
printf("[thread %s] Interval OnNext: %ld\n", get_pid().c_str(), v);
return v;
}).
take(7).
values.
[](std::vector<long> v){
printf("[thread %s] OnNext:", get_pid().c_str());
std::for_each(v.begin(), v.end(), [](long a){
printf(" %ld", a);
});
printf("\n");
},
[](){printf("[thread %s] OnCompleted\n", get_pid().c_str());});
printf("[thread %s] Finish task\n", get_pid().c_str());
[thread 47481267428736] Start task
[thread 47481267428736] Interval OnNext: 1
[thread 47481267428736] Interval OnNext: 2
[thread 47481294776064] OnNext: 1 2
[thread 47481267428736] Interval OnNext: 3
[thread 47481267428736] Interval OnNext: 4
[thread 47481267428736] Interval OnNext: 5
[thread 47481294776064] OnNext: 4 5
[thread 47481267428736] Interval OnNext: 6
[thread 47481267428736] Interval OnNext: 7
[thread 47481294776064] OnNext: 7
[thread 47481294776064] OnCompleted
[thread 47481267428736] Finish task
Sample Code
auto period = std::chrono::milliseconds(4);
auto skip = std::chrono::milliseconds(6);
auto values = rxcpp::observable<>::interval(std::chrono::steady_clock::now() + std::chrono::milliseconds(1), std::chrono::milliseconds(2)).
take(7).
values.
[](std::vector<long> v){
printf("OnNext:");
std::for_each(v.begin(), v.end(), [](long a){
printf(" %ld", a);
});
printf("\n");
},
[](){printf("OnCompleted\n");});
OnNext: 1 2
OnNext: 4 5
OnNext: 7
OnCompleted
Overlapping buffers are allowed:
auto period = std::chrono::milliseconds(6);
auto skip = std::chrono::milliseconds(4);
auto values = rxcpp::observable<>::interval(std::chrono::steady_clock::now() + std::chrono::milliseconds(1), std::chrono::milliseconds(2)).
take(7).
values.
[](std::vector<long> v){
printf("OnNext:");
std::for_each(v.begin(), v.end(), [](long a){
printf(" %ld", a);
});
printf("\n");
},
[](){printf("OnCompleted\n");});
OnNext: 1 2 3
OnNext: 3 4 5
OnNext: 5 6 7
OnNext: 7
OnCompleted
If no items are emitted, an empty buffer is returned:
auto period = std::chrono::milliseconds(2);
auto skip = std::chrono::milliseconds(4);
auto values = rxcpp::observable<>::timer(std::chrono::milliseconds(10)).
values.
[](std::vector<long> v){
printf("OnNext:");
std::for_each(v.begin(), v.end(), [](long a){
printf(" %ld", a);
});
printf("\n");
},
[](){printf("OnCompleted\n");});
OnNext:
OnNext:
OnNext: 1
OnCompleted
Sample Code
auto values = rxcpp::observable<>::interval(std::chrono::steady_clock::now() + std::chrono::milliseconds(1), std::chrono::milliseconds(2)).
take(7).
buffer_with_time(std::chrono::milliseconds(4), rxcpp::observe_on_new_thread());
values.
[](std::vector<long> v){
printf("OnNext:");
std::for_each(v.begin(), v.end(), [](long a){
printf(" %ld", a);
});
printf("\n");
},
[](){printf("OnCompleted\n");});
OnNext: 1 2
OnNext: 3 4
OnNext: 5 6
OnNext: 7
OnCompleted
Sample Code
auto values = rxcpp::observable<>::interval(std::chrono::steady_clock::now() + std::chrono::milliseconds(1), std::chrono::milliseconds(2)).
take(7).
buffer_with_time(std::chrono::milliseconds(4));
values.
[](std::vector<long> v){
printf("OnNext:");
std::for_each(v.begin(), v.end(), [](long a){
printf(" %ld", a);
});
printf("\n");
},
[](){printf("OnCompleted\n");});
OnNext: 1 2
OnNext: 3 4
OnNext: 5 6
OnNext: 7
OnCompleted

Macro Definition Documentation

#define RXCPP_OPERATORS_RX_BUFFER_WITH_TIME_HPP