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... >
 

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\n
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 3070107664] Start task
[thread 3070107664] Interval OnNext: 1
[thread 3070107664] Interval OnNext: 2
[thread 3065996352] OnNext: 1 2
[thread 3070107664] Interval OnNext: 3
[thread 3070107664] Interval OnNext: 4
[thread 3070107664] Interval OnNext: 5
[thread 3065996352] OnNext: 4 5
[thread 3070107664] Interval OnNext: 6
[thread 3070107664] Interval OnNext: 7
[thread 3065996352] OnNext: 7
[thread 3065996352] OnCompleted
[thread 3070107664] Finish task
Sample Code\n
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\n
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\n
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

◆ RXCPP_OPERATORS_RX_BUFFER_WITH_TIME_HPP

#define RXCPP_OPERATORS_RX_BUFFER_WITH_TIME_HPP
rxcpp::sources::timer
auto timer(TimePointOrDuration when) -> typename std::enable_if< detail::defer_timer< TimePointOrDuration, identity_one_worker >::value, typename detail::defer_timer< TimePointOrDuration, identity_one_worker >::observable_type >::type
Definition: rx-timer.hpp:114
rxcpp::operators::map
auto map(AN &&... an) -> operator_factory< map_tag, AN... >
Definition: rx-map.hpp:105
rxcpp::observe_on_new_thread
observe_on_one_worker observe_on_new_thread()
Definition: rx-observe_on.hpp:328
rxcpp::operators::skip
auto skip(AN &&... an) -> operator_factory< skip_tag, AN... >
Definition: rx-skip.hpp:130
rxcpp::operators::as_blocking
auto as_blocking() -> detail::blocking_factory
Definition: rx-subscribe.hpp:144
rxcpp::operators::take
auto take(AN &&... an) -> operator_factory< take_tag, AN... >
Definition: rx-take.hpp:133
rxcpp::operators::subscribe
auto subscribe(ArgN &&... an) -> detail::subscribe_factory< decltype(make_subscriber< T >(std::forward< ArgN >(an)...))>
Definition: rx-subscribe.hpp:87
rxcpp::sources::interval
auto interval(Duration period) -> typename std::enable_if< detail::defer_interval< Duration, identity_one_worker >::value, typename detail::defer_interval< Duration, identity_one_worker >::observable_type >::type
Definition: rx-interval.hpp:113
rxcpp::operators::buffer_with_time
auto buffer_with_time(AN &&... an) -> operator_factory< buffer_with_time_tag, AN... >
Definition: rx-buffer_time.hpp:256