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 >>
 Returns an observable that executes the specified function when a subscriber subscribes to it. More...
 
template<class ObservableFactory >
auto defer (ObservableFactory of) -> observable< rxu::value_type_t< detail::defer_traits< ObservableFactory >>, detail::defer< ObservableFactory >>
 Returns an observable that calls the specified observable factory to create an observable for each new observer that subscribes. More...
 
template<class T >
auto empty () -> decltype(from< T >())
 Returns an observable that sends no items to observer and immediately completes, on the specified scheduler. More...
 
template<class T , class Coordination >
auto empty (Coordination cn) -> decltype(from< T >(std::move(cn)))
 Returns an observable that sends no items to observer and immediately completes, on the specified scheduler. More...
 
template<class T , class E >
auto error (E e) -> decltype(detail::make_error< T >(typename std::conditional< std::is_same< std::exception_ptr, rxu::decay_t< E >>::value, detail::throw_ptr_tag, detail::throw_instance_tag >::type(), std::move(e), identity_immediate()))
 Returns an observable that sends no items to observer and immediately generates an error, on the specified scheduler. More...
 
template<class T , class E , class Coordination >
auto error (E e, Coordination cn) -> decltype(detail::make_error< T >(typename std::conditional< std::is_same< std::exception_ptr, rxu::decay_t< E >>::value, detail::throw_ptr_tag, detail::throw_instance_tag >::type(), std::move(e), std::move(cn)))
 Returns an observable that sends no items to observer and immediately generates an error, on the specified scheduler. More...
 
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
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
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
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
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
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
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
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
template<class Collection >
auto iterate (Collection c) -> observable< rxu::value_type_t< detail::iterate_traits< Collection >>, detail::iterate< Collection, identity_one_worker >>
 Returns an observable that sends each value in the collection, on the specified scheduler. More...
 
template<class Collection , class Coordination >
auto iterate (Collection c, Coordination cn) -> observable< rxu::value_type_t< detail::iterate_traits< Collection >>, detail::iterate< Collection, Coordination >>
 Returns an observable that sends each value in the collection, on the specified scheduler. More...
 
template<class T >
auto from () -> decltype(iterate(std::array< T, 0 >(), identity_immediate()))
 
template<class T , class Coordination >
auto from (Coordination cn) -> typename std::enable_if< is_coordination< Coordination >::value, decltype( iterate(std::array< T, 0 >(), 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 >>
 Returns an observable that executes the specified function when a subscriber subscribes to it. More...
 
template<class T , class Coordination >
auto range (T first, T last, std::ptrdiff_t step, Coordination cn) -> observable< T, detail::range< T, Coordination >>
 Returns an observable that executes the specified function when a subscriber subscribes to it. More...
 
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
 Returns an observable that executes the specified function when a subscriber subscribes to it. More...
 
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
 Returns an observable that executes the specified function when a subscriber subscribes to it. More...
 
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 >>
 Returns an observable that makes an observable by the specified observable factory using the resource provided by the specified resource factory for each new observer that subscribes. More...
 
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
 Returns an observable that emits an integer at the specified time point. More...
 
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
 Returns an observable that emits an integer at the specified time point. More...
 

Function Documentation

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

Returns an observable that executes the specified function when a subscriber subscribes to it.

Template Parameters
Tthe type of the items that this observable emits
OnSubscribethe type of OnSubscribe handler function
Parameters
osOnSubscribe event handler
Returns
Observable that executes the specified function when a Subscriber subscribes to it.
Sample Code
auto ints = rxcpp::observable<>::create<int>(
s.on_next(1);
s.on_next(2);
s.on_completed();
});
ints.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnCompleted
Warning
It is good practice to check the observer's is_subscribed state from within the function you pass to create so that your observable can stop emitting items or doing expensive calculations when there is no longer an interested observer.
Bad Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnNext(3)
Just sent: OnNext(4)
Just sent: OnCompleted()
Good Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnCompleted()
Warning
It is good practice to use operators like observable::take to control lifetime rather than use the subscription explicitly.
Good Code
auto ints = rxcpp::observable<>::create<int>(
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
});
ints.
take(2).
[](int v){
printf("OnNext: %d\n", v);
},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){
printf("OnCompleted\n");
});
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
OnCompleted
Just sent: OnNext(1)
Just sent: OnCompleted()
template<class ObservableFactory >
auto rxcpp::sources::defer ( ObservableFactory  of) -> observable<rxu::value_type_t<detail::defer_traits<ObservableFactory>>, detail::defer<ObservableFactory>>

Returns an observable that calls the specified observable factory to create an observable for each new observer that subscribes.

Template Parameters
ObservableFactorythe type of the observable factory
Parameters
ofthe observable factory function to invoke for each observer that subscribes to the resulting observable
Returns
observable whose observers' subscriptions trigger an invocation of the given observable factory function
Sample Code
auto observable_factory = [](){return rxcpp::observable<>::range(1, 3);};
auto values = rxcpp::observable<>::defer(observable_factory);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
template<class T >
auto rxcpp::sources::empty ( ) -> decltype(from<T>())

Returns an observable that sends no items to observer and immediately completes, on the specified scheduler.

Template Parameters
Tthe type of (not) emitted items
Coordinationthe type of the scheduler (optional)
Parameters
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends no items to observer and immediately completes.
Sample Code
auto values = rxcpp::observable<>::empty<int>();
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnCompleted
Sample Code
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnCompleted
template<class T , class Coordination >
auto rxcpp::sources::empty ( Coordination  cn) -> decltype(from<T>(std::move(cn)))

Returns an observable that sends no items to observer and immediately completes, on the specified scheduler.

Template Parameters
Tthe type of (not) emitted items
Coordinationthe type of the scheduler (optional)
Parameters
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends no items to observer and immediately completes.
Sample Code
auto values = rxcpp::observable<>::empty<int>();
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnCompleted
Sample Code
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnCompleted
template<class T , class E >
auto rxcpp::sources::error ( e) -> decltype(detail::make_error<T>(typename std::conditional<std::is_same<std::exception_ptr, rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e), identity_immediate()))

Returns an observable that sends no items to observer and immediately generates an error, on the specified scheduler.

Template Parameters
Tthe type of (not) emitted items
Exceptionthe type of the error
Coordinationthe type of the scheduler (optional)
Parameters
ethe error to be passed to observers
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends no items to observer and immediately generates an error.
Sample Code
auto values = rxcpp::observable<>::error<int>(std::runtime_error("Error from source"));
values.
[](int v){printf("OnNext: %d\n", v);},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){printf("OnCompleted\n");});
OnError: Error from source
Sample Code
auto values = rxcpp::observable<>::error<int>(std::runtime_error("Error from source"), rxcpp::observe_on_event_loop());
values.
[](int v){printf("OnNext: %d\n", v);},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){printf("OnCompleted\n");});
OnError: Error from source
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<std::exception_ptr, rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e), std::move(cn)))

Returns an observable that sends no items to observer and immediately generates an error, on the specified scheduler.

Template Parameters
Tthe type of (not) emitted items
Exceptionthe type of the error
Coordinationthe type of the scheduler (optional)
Parameters
ethe error to be passed to observers
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends no items to observer and immediately generates an error.
Sample Code
auto values = rxcpp::observable<>::error<int>(std::runtime_error("Error from source"));
values.
[](int v){printf("OnNext: %d\n", v);},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){printf("OnCompleted\n");});
OnError: Error from source
Sample Code
auto values = rxcpp::observable<>::error<int>(std::runtime_error("Error from source"), rxcpp::observe_on_event_loop());
values.
[](int v){printf("OnNext: %d\n", v);},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){printf("OnCompleted\n");});
OnError: Error from source
template<class T >
auto rxcpp::sources::from ( ) -> decltype(iterate(std::array<T, 0>(), 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.
template<class T , class Coordination >
auto rxcpp::sources::from ( Coordination  cn) -> typename std::enable_if<is_coordination<Coordination>::value, decltype( iterate(std::array<T, 0>(), 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.
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
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.
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
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 47481267428736] Start task
[thread 47481303181056] Emit value: 1
[thread 47481303181056] OnNext: 1
[thread 47481303181056] Emit value: 2
[thread 47481303181056] OnNext: 2
[thread 47481303181056] Emit value: 3
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
Note
This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.
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

Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler.

Template Parameters
Coordinationthe type of the scheduler (optional)
Parameters
periodperiod between emitted values
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends a sequential integer each time interval
Sample Code
auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto start = scheduler.now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
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

Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler.

Template Parameters
Coordinationthe type of the scheduler (optional)
Parameters
periodperiod between emitted values
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends a sequential integer each time interval
Sample Code
auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto start = scheduler.now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
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

Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler.

Template Parameters
Coordinationthe type of the scheduler (optional)
Parameters
periodperiod between emitted values
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends a sequential integer each time interval
Sample Code
auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto start = scheduler.now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
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

Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler.

Template Parameters
Coordinationthe type of the scheduler (optional)
Parameters
periodperiod between emitted values
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends a sequential integer each time interval
Sample Code
auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto start = scheduler.now() + std::chrono::milliseconds(1);
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(start, period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
auto scheduler = rxcpp::identity_current_thread();
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::interval(period, scheduler);
values.
take(3).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
template<class Collection >
auto rxcpp::sources::iterate ( Collection  c) -> observable<rxu::value_type_t<detail::iterate_traits<Collection>>, detail::iterate<Collection, identity_one_worker>>

Returns an observable that sends each value in the collection, on the specified scheduler.

Template Parameters
Collectionthe type of the collection of values that this observable emits
Coordinationthe type of the scheduler (optional)
Parameters
ccollection containing values to send
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends each value in the collection.
Sample Code
std::array< int, 3 > a={{1, 2, 3}};
auto values = rxcpp::observable<>::iterate(a);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
std::array< int, 3 > a={{1, 2, 3}};
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
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>>

Returns an observable that sends each value in the collection, on the specified scheduler.

Template Parameters
Collectionthe type of the collection of values that this observable emits
Coordinationthe type of the scheduler (optional)
Parameters
ccollection containing values to send
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that sends each value in the collection.
Sample Code
std::array< int, 3 > a={{1, 2, 3}};
auto values = rxcpp::observable<>::iterate(a);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
Sample Code
std::array< int, 3 > a={{1, 2, 3}};
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnCompleted
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
auto values = rxcpp::observable<>::just(1);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
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
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
template<class T >
auto rxcpp::sources::never ( ) -> observable<T, detail::never<T>>

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

Returns an observable that executes the specified function when a subscriber subscribes to it.

Template Parameters
Tthe type of the items that this observable emits
OnSubscribethe type of OnSubscribe handler function
Parameters
osOnSubscribe event handler
Returns
Observable that executes the specified function when a Subscriber subscribes to it.
Sample Code
auto ints = rxcpp::observable<>::create<int>(
s.on_next(1);
s.on_next(2);
s.on_completed();
});
ints.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnCompleted
Warning
It is good practice to check the observer's is_subscribed state from within the function you pass to create so that your observable can stop emitting items or doing expensive calculations when there is no longer an interested observer.
Bad Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnNext(3)
Just sent: OnNext(4)
Just sent: OnCompleted()
Good Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnCompleted()
Warning
It is good practice to use operators like observable::take to control lifetime rather than use the subscription explicitly.
Good Code
auto ints = rxcpp::observable<>::create<int>(
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
});
ints.
take(2).
[](int v){
printf("OnNext: %d\n", v);
},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){
printf("OnCompleted\n");
});
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
OnCompleted
Just sent: OnNext(1)
Just sent: OnCompleted()
template<class T , class Coordination >
auto rxcpp::sources::range ( first,
last,
std::ptrdiff_t  step,
Coordination  cn 
) -> observable<T, detail::range<T, Coordination>>

Returns an observable that executes the specified function when a subscriber subscribes to it.

Template Parameters
Tthe type of the items that this observable emits
OnSubscribethe type of OnSubscribe handler function
Parameters
osOnSubscribe event handler
Returns
Observable that executes the specified function when a Subscriber subscribes to it.
Sample Code
auto ints = rxcpp::observable<>::create<int>(
s.on_next(1);
s.on_next(2);
s.on_completed();
});
ints.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnCompleted
Warning
It is good practice to check the observer's is_subscribed state from within the function you pass to create so that your observable can stop emitting items or doing expensive calculations when there is no longer an interested observer.
Bad Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnNext(3)
Just sent: OnNext(4)
Just sent: OnCompleted()
Good Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnCompleted()
Warning
It is good practice to use operators like observable::take to control lifetime rather than use the subscription explicitly.
Good Code
auto ints = rxcpp::observable<>::create<int>(
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
});
ints.
take(2).
[](int v){
printf("OnNext: %d\n", v);
},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){
printf("OnCompleted\n");
});
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
OnCompleted
Just sent: OnNext(1)
Just sent: OnCompleted()
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

Returns an observable that executes the specified function when a subscriber subscribes to it.

Template Parameters
Tthe type of the items that this observable emits
OnSubscribethe type of OnSubscribe handler function
Parameters
osOnSubscribe event handler
Returns
Observable that executes the specified function when a Subscriber subscribes to it.
Sample Code
auto ints = rxcpp::observable<>::create<int>(
s.on_next(1);
s.on_next(2);
s.on_completed();
});
ints.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnCompleted
Warning
It is good practice to check the observer's is_subscribed state from within the function you pass to create so that your observable can stop emitting items or doing expensive calculations when there is no longer an interested observer.
Bad Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnNext(3)
Just sent: OnNext(4)
Just sent: OnCompleted()
Good Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnCompleted()
Warning
It is good practice to use operators like observable::take to control lifetime rather than use the subscription explicitly.
Good Code
auto ints = rxcpp::observable<>::create<int>(
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
});
ints.
take(2).
[](int v){
printf("OnNext: %d\n", v);
},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){
printf("OnCompleted\n");
});
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
OnCompleted
Just sent: OnNext(1)
Just sent: OnCompleted()
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

Returns an observable that executes the specified function when a subscriber subscribes to it.

Template Parameters
Tthe type of the items that this observable emits
OnSubscribethe type of OnSubscribe handler function
Parameters
osOnSubscribe event handler
Returns
Observable that executes the specified function when a Subscriber subscribes to it.
Sample Code
auto ints = rxcpp::observable<>::create<int>(
s.on_next(1);
s.on_next(2);
s.on_completed();
});
ints.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnCompleted
Warning
It is good practice to check the observer's is_subscribed state from within the function you pass to create so that your observable can stop emitting items or doing expensive calculations when there is no longer an interested observer.
Bad Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnNext(3)
Just sent: OnNext(4)
Just sent: OnCompleted()
Good Code
auto subscription = rxcpp::composite_subscription();
auto subscriber = rxcpp::make_subscriber<int>(
subscription,
[&](int v){
printf("OnNext: %d\n", v);
if (v == 2)
subscription.unsubscribe();
},
[](){
printf("OnCompleted\n");
});
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
}).subscribe(subscriber);
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
Just sent: OnNext(1)
OnNext: 2
Just sent: OnNext(2)
Just sent: OnCompleted()
Warning
It is good practice to use operators like observable::take to control lifetime rather than use the subscription explicitly.
Good Code
auto ints = rxcpp::observable<>::create<int>(
for (int i = 0; i < 5; ++i) {
if (!s.is_subscribed()) // Stop emitting if nobody is listening
break;
s.on_next(i);
printf("Just sent: OnNext(%d)\n", i);
}
s.on_completed();
printf("Just sent: OnCompleted()\n");
});
ints.
take(2).
[](int v){
printf("OnNext: %d\n", v);
},
[](std::exception_ptr ep){
try {std::rethrow_exception(ep);}
catch (const std::exception& ex) {
printf("OnError: %s\n", ex.what());
}
},
[](){
printf("OnCompleted\n");
});
OnNext: 0
Just sent: OnNext(0)
OnNext: 1
OnCompleted
Just sent: OnNext(1)
Just sent: OnCompleted()
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>>

Returns an observable that makes an observable by the specified observable factory using the resource provided by the specified resource factory for each new observer that subscribes.

Template Parameters
ResourceFactorythe type of the resource factory
ObservableFactorythe type of the observable factory
Parameters
rfthe resource factory function that resturn the rxcpp::resource that is used as a resource by the observable factory
ofthe observable factory function to invoke for each observer that subscribes to the resulting observable
Returns
observable that makes an observable by the specified observable factory using the resource provided by the specified resource factory for each new observer that subscribes.
Sample Code
auto resource_factory = [](){return resource(rxcpp::util::to_vector({1, 2, 3, 4, 5}));};
auto observable_factory = [](resource res){return rxcpp::observable<>::iterate(res.get());};
auto values = rxcpp::observable<>::scope(resource_factory, observable_factory);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnNext: 4
OnNext: 5
OnCompleted
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
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
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

Returns an observable that emits an integer at the specified time point.

Template Parameters
Coordinationthe type of the scheduler (optional)
Parameters
whentime point when the value is emitted
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that emits an integer at the specified time point
Sample Code
auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(start);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Sample Code
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(period);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Sample Code
auto scheduler = rxcpp::observe_on_new_thread();
auto start = scheduler.now() + std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(start, scheduler);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Sample Code
auto scheduler = rxcpp::observe_on_new_thread();
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(period, scheduler);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
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

Returns an observable that emits an integer at the specified time point.

Template Parameters
Coordinationthe type of the scheduler (optional)
Parameters
whentime point when the value is emitted
cnthe scheduler to use for scheduling the items (optional)
Returns
Observable that emits an integer at the specified time point
Sample Code
auto start = std::chrono::steady_clock::now() + std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(start);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Sample Code
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(period);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Sample Code
auto scheduler = rxcpp::observe_on_new_thread();
auto start = scheduler.now() + std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(start, scheduler);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Sample Code
auto scheduler = rxcpp::observe_on_new_thread();
auto period = std::chrono::milliseconds(1);
auto values = rxcpp::observable<>::timer(period, scheduler);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted