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 | Functions
rxcpp::sources Namespace Reference

Classes

class  is_source
 
struct  source_base
 
struct  tag_source
 

Functions

template<class T , class OnSubscribe >
auto create (OnSubscribe os) -> observable< T, detail::create< T, OnSubscribe >>
 
template<class ObservableFactory >
auto defer (ObservableFactory of) -> observable< rxu::value_type_t< detail::defer_traits< ObservableFactory >>, detail::defer< ObservableFactory >>
 
template<class T >
auto empty () -> decltype(from< T >())
 
template<class T , class Coordination >
auto empty (Coordination cn) -> decltype(from< T >(std::move(cn)))
 
template<class T , class E >
auto error (E e) -> decltype(detail::make_error< T >(typename std::conditional< std::is_same< rxu::error_ptr, rxu::decay_t< E >>::value, detail::throw_ptr_tag, detail::throw_instance_tag >::type(), std::move(e), identity_immediate()))
 
template<class T , class E , class Coordination >
auto error (E e, Coordination cn) -> decltype(detail::make_error< T >(typename std::conditional< std::is_same< rxu::error_ptr, rxu::decay_t< E >>::value, detail::throw_ptr_tag, detail::throw_instance_tag >::type(), std::move(e), std::move(cn)))
 
template<class Duration >
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
 
template<class Coordination >
auto interval (rxsc::scheduler::clock_type::duration period, Coordination cn) -> typename std::enable_if< detail::defer_interval< rxsc::scheduler::clock_type::duration, Coordination >::value, typename detail::defer_interval< rxsc::scheduler::clock_type::duration, Coordination >::observable_type >::type
 
template<class Duration >
auto interval (rxsc::scheduler::clock_type::time_point when, 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
 
template<class Coordination >
auto interval (rxsc::scheduler::clock_type::time_point when, rxsc::scheduler::clock_type::duration period, Coordination cn) -> typename std::enable_if< detail::defer_interval< rxsc::scheduler::clock_type::duration, Coordination >::value, typename detail::defer_interval< rxsc::scheduler::clock_type::duration, Coordination >::observable_type >::type
 
template<class Collection >
auto iterate (Collection c) -> observable< rxu::value_type_t< detail::iterate_traits< Collection >>, detail::iterate< Collection, identity_one_worker >>
 
template<class Collection , class Coordination >
auto iterate (Collection c, Coordination cn) -> observable< rxu::value_type_t< detail::iterate_traits< Collection >>, detail::iterate< Collection, Coordination >>
 
template<class T >
auto from () -> decltype(iterate(std::initializer_list< T >(), identity_immediate()))
 
template<class T , class Coordination >
auto from (Coordination cn) -> typename std::enable_if< is_coordination< Coordination >::value, decltype(iterate(std::initializer_list< T >(), std::move(cn)))>::type
 
template<class Value0 , class... ValueN>
auto from (Value0 v0, ValueN... vn) -> typename std::enable_if<!is_coordination< Value0 >::value, decltype(iterate(*(std::array< Value0, sizeof...(ValueN)+1 > *) nullptr, identity_immediate()))>::type
 
template<class Coordination , class Value0 , class... ValueN>
auto from (Coordination cn, Value0 v0, ValueN... vn) -> typename std::enable_if< is_coordination< Coordination >::value, decltype(iterate(*(std::array< Value0, sizeof...(ValueN)+1 > *) nullptr, std::move(cn)))>::type
 
template<class Value0 >
auto just (Value0 v0) -> typename std::enable_if<!is_coordination< Value0 >::value, decltype(iterate(*(std::array< Value0, 1 > *) nullptr, identity_immediate()))>::type
 
template<class Value0 , class Coordination >
auto just (Value0 v0, Coordination cn) -> typename std::enable_if< is_coordination< Coordination >::value, decltype(iterate(*(std::array< Value0, 1 > *) nullptr, std::move(cn)))>::type
 
template<class Observable , class Value0 , class... ValueN>
auto start_with (Observable o, Value0 v0, ValueN... vn) -> decltype(from(rxu::value_type_t< Observable >(v0), rxu::value_type_t< Observable >(vn)...).concat(o))
 
template<class T >
auto never () -> observable< T, detail::never< T >>
 
template<class T >
auto range (T first=0, T last=std::numeric_limits< T >::max(), std::ptrdiff_t step=1) -> observable< T, detail::range< T, identity_one_worker >>
 
template<class T , class Coordination >
auto range (T first, T last, std::ptrdiff_t step, Coordination cn) -> observable< T, detail::range< T, Coordination >>
 
template<class T , class Coordination >
auto range (T first, T last, Coordination cn) -> typename std::enable_if< is_coordination< Coordination >::value, observable< T, detail::range< T, Coordination >>>::type
 
template<class T , class Coordination >
auto range (T first, Coordination cn) -> typename std::enable_if< is_coordination< Coordination >::value, observable< T, detail::range< T, Coordination >>>::type
 
template<class ResourceFactory , class ObservableFactory >
auto scope (ResourceFactory rf, ObservableFactory of) -> observable< rxu::value_type_t< detail::scope_traits< ResourceFactory, ObservableFactory >>, detail::scope< ResourceFactory, ObservableFactory >>
 
template<class TimePointOrDuration >
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
 
template<class TimePointOrDuration , class Coordination >
auto timer (TimePointOrDuration when, Coordination cn) -> typename std::enable_if< detail::defer_timer< TimePointOrDuration, Coordination >::value, typename detail::defer_timer< TimePointOrDuration, Coordination >::observable_type >::type
 

Function Documentation

◆ create()

template<class T , class OnSubscribe >
auto rxcpp::sources::create ( OnSubscribe  os) -> observable<T, detail::create<T, OnSubscribe>>

◆ defer()

template<class ObservableFactory >
auto rxcpp::sources::defer ( ObservableFactory  of) -> observable<rxu::value_type_t<detail::defer_traits<ObservableFactory>>, detail::defer<ObservableFactory>>

◆ empty() [1/2]

template<class T >
auto rxcpp::sources::empty ( ) -> decltype(from<T>())

◆ empty() [2/2]

template<class T , class Coordination >
auto rxcpp::sources::empty ( Coordination  cn) -> decltype(from<T>(std::move(cn)))

◆ error() [1/2]

template<class T , class E >
auto rxcpp::sources::error ( e) -> decltype(detail::make_error<T>(typename std::conditional<std::is_same<rxu::error_ptr, rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e), identity_immediate()))

◆ error() [2/2]

template<class T , class E , class Coordination >
auto rxcpp::sources::error ( e,
Coordination  cn 
) -> decltype(detail::make_error<T>(typename std::conditional<std::is_same<rxu::error_ptr, rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e), std::move(cn)))

◆ from() [1/4]

template<class T >
auto rxcpp::sources::from ( ) -> decltype(iterate(std::initializer_list<T>(), identity_immediate()))

Returns an observable that sends an empty set of values and then completes.

Template Parameters
Tthe type of elements (not) to be sent
Returns
Observable that sends an empty set of values and then completes.

This is a degenerate case of rxcpp::observable<void,void>::from(Value0,ValueN...) operator.

Note
This is a degenerate case of from(Value0 v0, ValueN... vn) operator.

◆ from() [2/4]

template<class T , class Coordination >
auto rxcpp::sources::from ( Coordination  cn) -> typename std::enable_if<is_coordination<Coordination>::value, decltype( iterate(std::initializer_list<T>(), std::move(cn)))>::type

Returns an observable that sends an empty set of values and then completes, on the specified scheduler.

Template Parameters
Tthe type of elements (not) to be sent
Coordinationthe type of the scheduler
Returns
Observable that sends an empty set of values and then completes.
Note
This is a degenerate case of from(Coordination cn, Value0 v0, ValueN... vn) operator.

◆ from() [3/4]

template<class Coordination , class Value0 , class... ValueN>
auto rxcpp::sources::from ( Coordination  cn,
Value0  v0,
ValueN...  vn 
) -> typename std::enable_if<is_coordination<Coordination>::value, decltype(iterate(*(std::array<Value0, sizeof...(ValueN) + 1>*)nullptr, std::move(cn)))>::type

Returns an observable that sends each value from its arguments list, on the specified scheduler.

Template Parameters
Coordinationthe type of the scheduler
Value0...
ValueNthe type of sending values
Parameters
cnthe scheduler to use for scheduling the items
v0...
vnvalues to send
Returns
Observable that sends each value from its arguments list.
Sample Code\n
printf("[thread %s] Start task\n", get_pid().c_str());
auto values = rxcpp::observable<>::from(rxcpp::observe_on_new_thread(), 1, 2, 3).map([](int v){
printf("[thread %s] Emit value: %d\n", get_pid().c_str(), v);
return v;
});
values.
[](int v){printf("[thread %s] OnNext: %d\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 3015701568] Emit value: 1
[thread 3015701568] OnNext: 1
[thread 3015701568] Emit value: 2
[thread 3015701568] OnNext: 2
[thread 3015701568] Emit value: 3
[thread 3015701568] OnNext: 3
[thread 3015701568] OnCompleted
[thread 3070107664] Finish task
Note
This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.

◆ from() [4/4]

template<class Value0 , class... ValueN>
auto rxcpp::sources::from ( Value0  v0,
ValueN...  vn 
) -> typename std::enable_if<!is_coordination<Value0>::value, decltype(iterate(*(std::array<Value0, sizeof...(ValueN) + 1>*)nullptr, identity_immediate()))>::type

Returns an observable that sends each value from its arguments list.

Template Parameters
Value0...
ValueNthe type of sending values
Parameters
v0...
vnvalues to send
Returns
Observable that sends each value from its arguments list.
Sample Code\n
auto values = rxcpp::observable<>::from(1, 2, 3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Note
This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.

◆ interval() [1/4]

template<class Duration >
auto rxcpp::sources::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

◆ interval() [2/4]

template<class Coordination >
auto rxcpp::sources::interval ( rxsc::scheduler::clock_type::duration  period,
Coordination  cn 
) -> typename std::enable_if< detail::defer_interval<rxsc::scheduler::clock_type::duration, Coordination>::value, typename detail::defer_interval<rxsc::scheduler::clock_type::duration, Coordination>::observable_type>::type

◆ interval() [3/4]

template<class Duration >
auto rxcpp::sources::interval ( rxsc::scheduler::clock_type::time_point  when,
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

◆ interval() [4/4]

template<class Coordination >
auto rxcpp::sources::interval ( rxsc::scheduler::clock_type::time_point  when,
rxsc::scheduler::clock_type::duration  period,
Coordination  cn 
) -> typename std::enable_if< detail::defer_interval<rxsc::scheduler::clock_type::duration, Coordination>::value, typename detail::defer_interval<rxsc::scheduler::clock_type::duration, Coordination>::observable_type>::type

◆ iterate() [1/2]

template<class Collection >
auto rxcpp::sources::iterate ( Collection  c) -> observable<rxu::value_type_t<detail::iterate_traits<Collection>>, detail::iterate<Collection, identity_one_worker>>

◆ iterate() [2/2]

template<class Collection , class Coordination >
auto rxcpp::sources::iterate ( Collection  c,
Coordination  cn 
) -> observable<rxu::value_type_t<detail::iterate_traits<Collection>>, detail::iterate<Collection, Coordination>>

◆ just() [1/2]

template<class Value0 >
auto rxcpp::sources::just ( Value0  v0) -> typename std::enable_if<!is_coordination<Value0>::value, decltype(iterate(*(std::array<Value0, 1>*)nullptr, identity_immediate()))>::type

Returns an observable that sends the specified item to observer and then completes.

Template Parameters
Tthe type of the emitted item
Parameters
vthe value to send
Returns
Observable that sends the specified item to observer and then completes.
Sample Code\n
auto values = rxcpp::observable<>::just(1);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted

◆ just() [2/2]

template<class Value0 , class Coordination >
auto rxcpp::sources::just ( Value0  v0,
Coordination  cn 
) -> typename std::enable_if<is_coordination<Coordination>::value, decltype(iterate(*(std::array<Value0, 1>*)nullptr, std::move(cn)))>::type

Returns an observable that sends the specified item to observer and then completes, on the specified scheduler.

Template Parameters
Tthe type of the emitted item
Coordinationthe type of the scheduler
Parameters
vthe value to send
cnthe scheduler to use for scheduling the items
Returns
Observable that sends the specified item to observer and then completes.
Sample Code\n
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted

◆ never()

template<class T >
auto rxcpp::sources::never ( ) -> observable<T, detail::never<T>>

◆ range() [1/4]

template<class T , class Coordination >
auto rxcpp::sources::range ( first,
Coordination  cn 
) -> typename std::enable_if<is_coordination<Coordination>::value, observable<T, detail::range<T, Coordination>>>::type

◆ range() [2/4]

template<class T , class Coordination >
auto rxcpp::sources::range ( first,
last,
Coordination  cn 
) -> typename std::enable_if<is_coordination<Coordination>::value, observable<T, detail::range<T, Coordination>>>::type

◆ range() [3/4]

template<class T , class Coordination >
auto rxcpp::sources::range ( first,
last,
std::ptrdiff_t  step,
Coordination  cn 
) -> observable<T, detail::range<T, Coordination>>

◆ range() [4/4]

template<class T >
auto rxcpp::sources::range ( first = 0,
last = std::numeric_limits<T>::max(),
std::ptrdiff_t  step = 1 
) -> observable<T, detail::range<T, identity_one_worker>>

◆ scope()

template<class ResourceFactory , class ObservableFactory >
auto rxcpp::sources::scope ( ResourceFactory  rf,
ObservableFactory  of 
) -> observable<rxu::value_type_t<detail::scope_traits<ResourceFactory, ObservableFactory>>, detail::scope<ResourceFactory, ObservableFactory>>

◆ start_with()

template<class Observable , class Value0 , class... ValueN>
auto rxcpp::sources::start_with ( Observable  o,
Value0  v0,
ValueN...  vn 
) -> decltype(from(rxu::value_type_t<Observable>(v0), rxu::value_type_t<Observable>(vn)...).concat(o))

Returns an observable that sends the specified values before it begins to send items emitted by the given observable.

Template Parameters
Observablethe type of the observable that emits values for resending
Value0...
ValueNthe type of sending values
Parameters
othe observable that emits values for resending
v0...
vnvalues to send
Returns
Observable that sends the specified values before it begins to send items emitted by the given observable.
Sample Code\n
auto observable = rxcpp::observable<>::range(10, 12);
auto values = rxcpp::observable<>::start_with(observable, 1, 2, 3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnNext: 10
OnNext: 11
OnNext: 12
OnCompleted
Instead of passing the observable as a parameter, you can use rxcpp::observable<T, SourceOperator>::start_with method of the existing observable:
auto values = rxcpp::observable<>::range(10, 12).
start_with(1, 2, 3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnNext: 10
OnNext: 11
OnNext: 12
OnCompleted

◆ timer() [1/2]

template<class TimePointOrDuration >
auto rxcpp::sources::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

◆ timer() [2/2]

template<class TimePointOrDuration , class Coordination >
auto rxcpp::sources::timer ( TimePointOrDuration  when,
Coordination  cn 
) -> typename std::enable_if< detail::defer_timer<TimePointOrDuration, Coordination>::value, typename detail::defer_timer<TimePointOrDuration, Coordination>::observable_type>::type

rxcpp::sources::range
auto range(T first=0, T last=std::numeric_limits< T >::max(), std::ptrdiff_t step=1) -> observable< T, detail::range< T, identity_one_worker >>
Definition: rx-range.hpp:119
rxcpp::observe_on_new_thread
observe_on_one_worker observe_on_new_thread()
Definition: rx-observe_on.hpp:328
rxcpp::sources::start_with
auto start_with(Observable o, Value0 v0, ValueN... vn) -> decltype(from(rxu::value_type_t< Observable >(v0), rxu::value_type_t< Observable >(vn)...).concat(o))
Definition: rx-iterate.hpp:316
cpplinq::from
linq_driver< iter_cursor< typename util::container_traits< TContainer >::iterator > > from(TContainer &c)
Definition: linq.hpp:556
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::observe_on_event_loop
observe_on_one_worker observe_on_event_loop()
Definition: rx-observe_on.hpp:323
rxcpp::sources::just
auto just(Value0 v0) -> typename std::enable_if<!is_coordination< Value0 >::value, decltype(iterate(*(std::array< Value0, 1 > *) nullptr, identity_immediate()))>::type
Definition: rx-iterate.hpp:267
rxcpp::observable::start_with
auto start_with(AN... an) const
Definition: rx-observable.hpp:1434