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-take_until.hpp File Reference

For each item from this observable until on_next occurs on the trigger observable or until the specified time, emit them from the new observable that is returned. take_until takes (TriggerObservable, optional Coordination) or (TimePoint, optional Coordination) More...

#include "../rx-includes.hpp"
Include dependency graph for rx-take_until.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< take_until_tag >
 

Namespaces

 rxcpp
 
 rxcpp::operators
 

Macros

#define RXCPP_OPERATORS_RX_TAKE_UNTIL_HPP
 

Functions

template<class... AN>
auto rxcpp::operators::take_until (AN &&... an) -> operator_factory< take_until_tag, AN... >
 

Detailed Description

For each item from this observable until on_next occurs on the trigger observable or until the specified time, emit them from the new observable that is returned. take_until takes (TriggerObservable, optional Coordination) or (TimePoint, optional Coordination)

Template Parameters
TriggerSourcethe type of the trigger observable.
TimePointthe type of the time interval.
Coordinationthe type of the scheduler (optional).
Parameters
tan observable whose first emitted item will stop emitting items from the source observable.
whena time point when the returned observable will stop emitting items.
cnthe scheduler to use for scheduling the items (optional).
Returns
An observable that emits the items emitted by the source observable until trigger observable emitted or the time runs out.
Sample Code\n
auto source = rxcpp::observable<>::interval(std::chrono::milliseconds(10)).take(7);
auto trigger = rxcpp::observable<>::timer(std::chrono::milliseconds(25));
auto values = source.take_until(trigger);
values.
[](long v){printf("OnNext: %ld\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code\n
printf("[thread %s] Start task\n", get_pid().c_str());
auto source = rxcpp::observable<>::interval(std::chrono::milliseconds(10)).take(7).map([](long v){
printf("[thread %s] Source emits, value = %ld\n", get_pid().c_str(), v);
return v;
});
auto trigger = rxcpp::observable<>::timer(std::chrono::milliseconds(25)).map([](long v){
printf("[thread %s] Trigger emits, value = %ld\n", get_pid().c_str(), v);
return v;
});
auto values = source.take_until(trigger, rxcpp::observe_on_new_thread());
values.
[](long v){printf("[thread %s] OnNext: %ld\n", get_pid().c_str(), v);},
[](){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] Source emits, value = 1
[thread 2967462976] OnNext: 1
[thread 3070107664] Source emits, value = 2
[thread 2967462976] OnNext: 2
[thread 3070107664] Source emits, value = 3
[thread 2967462976] OnNext: 3
[thread 3070107664] Trigger emits, value = 1
[thread 2967462976] OnCompleted
[thread 3070107664] Finish task
Sample Code\n
auto source = rxcpp::observable<>::interval(std::chrono::milliseconds(10)).take(7);
auto values = source.take_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(25));
values.
[](long v){printf("OnNext: %ld\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code\n
printf("[thread %s] Start task\n", get_pid().c_str());
auto source = rxcpp::observable<>::interval(std::chrono::milliseconds(10)).take(7).map([](long v){
printf("[thread %s] Source emits, value = %ld\n", get_pid().c_str(), v);
return v;
});
auto scheduler = rxcpp::observe_on_new_thread();
auto values = source.take_until(scheduler.now() + std::chrono::milliseconds(25), scheduler);
values.
[](long v){printf("[thread %s] OnNext: %ld\n", get_pid().c_str(), v);},
[](){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] Source emits, value = 1
[thread 2967462976] OnNext: 1
[thread 3070107664] Source emits, value = 2
[thread 2967462976] OnNext: 2
[thread 3070107664] Source emits, value = 3
[thread 2967462976] OnNext: 3
[thread 2967462976] OnCompleted
[thread 3070107664] Finish task

Macro Definition Documentation

◆ RXCPP_OPERATORS_RX_TAKE_UNTIL_HPP

#define RXCPP_OPERATORS_RX_TAKE_UNTIL_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::observe_on_new_thread
observe_on_one_worker observe_on_new_thread()
Definition: rx-observe_on.hpp:328
rxcpp::operators::as_blocking
auto as_blocking() -> detail::blocking_factory
Definition: rx-subscribe.hpp:144
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