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++.
Static Public Member Functions | List of all members
rxcpp::observable< void, void > Class Template Reference

typed as rxcpp::observable<>, this is a collection of factory methods that return an observable. More...

#include <rx-observable.hpp>

Static Public Member Functions

template<class T , class OnSubscribe >
static auto create (OnSubscribe os) -> decltype(rxs::create< T >(std::move(os)))
 Returns an observable that executes the specified function when a subscriber subscribes to it. More...
 
template<class T >
static auto range (T first=0, T last=std::numeric_limits< T >::max(), std::ptrdiff_t step=1) -> decltype(rxs::range< T >(first, last, step, identity_current_thread()))
 Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler. More...
 
template<class T , class Coordination >
static auto range (T first, T last, std::ptrdiff_t step, Coordination cn) -> decltype(rxs::range< T >(first, last, step, std::move(cn)))
 Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler. More...
 
template<class T , class Coordination >
static auto range (T first, T last, Coordination cn) -> decltype(rxs::range< T >(first, last, std::move(cn)))
 Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler. More...
 
template<class T , class Coordination >
static auto range (T first, Coordination cn) -> decltype(rxs::range< T >(first, std::move(cn)))
 Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler. More...
 
template<class T >
static auto never () -> decltype(rxs::never< T >())
 
template<class ObservableFactory >
static auto defer (ObservableFactory of) -> decltype(rxs::defer(std::move(of)))
 Returns an observable that calls the specified observable factory to create an observable for each new observer that subscribes. More...
 
template<class... AN>
static auto interval (rxsc::scheduler::clock_type::duration period, AN **...) -> decltype(rxs::interval(period))
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
template<class Coordination >
static auto interval (rxsc::scheduler::clock_type::duration period, Coordination cn) -> decltype(rxs::interval(period, std::move(cn)))
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
template<class... AN>
static auto interval (rxsc::scheduler::clock_type::time_point initial, rxsc::scheduler::clock_type::duration period, AN **...) -> decltype(rxs::interval(initial, period))
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
template<class Coordination >
static auto interval (rxsc::scheduler::clock_type::time_point initial, rxsc::scheduler::clock_type::duration period, Coordination cn) -> decltype(rxs::interval(initial, period, std::move(cn)))
 Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler. More...
 
template<class... AN>
static auto timer (rxsc::scheduler::clock_type::time_point at, AN **...) -> decltype(rxs::timer(at))
 Returns an observable that emits an integer at the specified time point. More...
 
template<class... AN>
static auto timer (rxsc::scheduler::clock_type::duration after, AN **...) -> decltype(rxs::timer(after))
 Returns an observable that emits an integer at the specified time point. More...
 
template<class Coordination >
static auto timer (rxsc::scheduler::clock_type::time_point when, Coordination cn) -> decltype(rxs::timer(when, std::move(cn)))
 Returns an observable that emits an integer at the specified time point. More...
 
template<class Coordination >
static auto timer (rxsc::scheduler::clock_type::duration when, Coordination cn) -> decltype(rxs::timer(when, std::move(cn)))
 Returns an observable that emits an integer at the specified time point. More...
 
template<class Collection >
static auto iterate (Collection c) -> decltype(rxs::iterate(std::move(c), identity_current_thread()))
 Returns an observable that sends each value in the collection, on the specified scheduler. More...
 
template<class Collection , class Coordination >
static auto iterate (Collection c, Coordination cn) -> decltype(rxs::iterate(std::move(c), std::move(cn)))
 Returns an observable that sends each value in the collection, on the specified scheduler. More...
 
template<class T >
static auto from () -> decltype( rxs::from< T >())
 
template<class T , class Coordination >
static auto from (Coordination cn) -> typename std::enable_if< is_coordination< Coordination >::value, decltype( rxs::from< T >(std::move(cn)))>::type
 
template<class Value0 , class... ValueN>
static auto from (Value0 v0, ValueN...vn) -> typename std::enable_if<!is_coordination< Value0 >::value, decltype( rxs::from(v0, vn...))>::type
 
template<class Coordination , class Value0 , class... ValueN>
static auto from (Coordination cn, Value0 v0, ValueN...vn) -> typename std::enable_if< is_coordination< Coordination >::value, decltype( rxs::from(std::move(cn), v0, vn...))>::type
 
template<class T >
static auto just (T v) -> decltype(rxs::just(std::move(v)))
 
template<class T , class Coordination >
static auto just (T v, Coordination cn) -> decltype(rxs::just(std::move(v), std::move(cn)))
 
template<class Observable , class Value0 , class... ValueN>
static auto start_with (Observable o, Value0 v0, ValueN...vn) -> decltype(rxs::start_with(std::move(o), std::move(v0), std::move(vn)...))
 
template<class T >
static 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 >
static 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 Exception >
static auto error (Exception &&e) -> decltype(rxs::error< T >(std::forward< Exception >(e)))
 Returns an observable that sends no items to observer and immediately generates an error, on the specified scheduler. More...
 
template<class T , class Exception , class Coordination >
static auto error (Exception &&e, Coordination cn) -> decltype(rxs::error< T >(std::forward< Exception >(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 ResourceFactory , class ObservableFactory >
static auto scope (ResourceFactory rf, ObservableFactory of) -> decltype(rxs::scope(std::move(rf), std::move(of)))
 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...
 

Detailed Description

template<>
class rxcpp::observable< void, void >

typed as rxcpp::observable<>, this is a collection of factory methods that return an observable.

Create a new type of observable
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
Create an observable that emits a range of values
Sample Code
auto values1 = rxcpp::observable<>::range(1, 5);
values1.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3
OnNext: 4
OnNext: 5
OnCompleted
Create an observable that emits nothing / generates an error / immediately completes
Sample Code
auto values = rxcpp::observable<>::never<int>();
values.
take_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(10)).
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnCompleted
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
auto values = rxcpp::observable<>::empty<int>();
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnCompleted
Create an observable that generates new observable for each subscriber
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
Create an observable that emits items every specified interval of time
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
Create an observable that emits items in the specified interval of time
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
Create an observable that emits all items from a 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
Create an observable that emits a set of specified items
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
Create an observable that emits a single item
Sample Code
auto values = rxcpp::observable<>::just(1);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 1
OnCompleted
Create an observable that emits a set of items and then subscribes to another 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
Create an observable that generates a new observable based on a generated resource for each subscriber
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

Member Function Documentation

template<class T , class OnSubscribe >
static auto rxcpp::observable< void, void >::create ( OnSubscribe  os) -> decltype(rxs::create<T>(std::move(os)))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::defer ( ObservableFactory  of) -> decltype(rxs::defer(std::move(of)))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::empty ( ) -> decltype(from<T>())
inlinestatic

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 >
static auto rxcpp::observable< void, void >::empty ( Coordination  cn) -> decltype(from<T>(std::move(cn)))
inlinestatic

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 Exception >
static auto rxcpp::observable< void, void >::error ( Exception &&  e) -> decltype(rxs::error<T>(std::forward<Exception>(e)))
inlinestatic

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 Exception , class Coordination >
static auto rxcpp::observable< void, void >::error ( Exception &&  e,
Coordination  cn 
) -> decltype(rxs::error<T>(std::forward<Exception>(e), std::move(cn)))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::from ( ) -> decltype( rxs::from<T>())
inlinestatic

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 >
static auto rxcpp::observable< void, void >::from ( Coordination  cn) -> typename std::enable_if<is_coordination<Coordination>::value, decltype( rxs::from<T>(std::move(cn)))>::type
inlinestatic

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>
static auto rxcpp::observable< void, void >::from ( Value0  v0,
ValueN...  vn 
) -> typename std::enable_if<!is_coordination<Value0>::value, decltype( rxs::from(v0, vn...))>::type
inlinestatic

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>
static auto rxcpp::observable< void, void >::from ( Coordination  cn,
Value0  v0,
ValueN...  vn 
) -> typename std::enable_if<is_coordination<Coordination>::value, decltype( rxs::from(std::move(cn), v0, vn...))>::type
inlinestatic

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... AN>
static auto rxcpp::observable< void, void >::interval ( rxsc::scheduler::clock_type::duration  period,
AN **  ... 
) -> decltype(rxs::interval(period))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::interval ( rxsc::scheduler::clock_type::duration  period,
Coordination  cn 
) -> decltype(rxs::interval(period, std::move(cn)))
inlinestatic

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... AN>
static auto rxcpp::observable< void, void >::interval ( rxsc::scheduler::clock_type::time_point  initial,
rxsc::scheduler::clock_type::duration  period,
AN **  ... 
) -> decltype(rxs::interval(initial, period))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::interval ( rxsc::scheduler::clock_type::time_point  initial,
rxsc::scheduler::clock_type::duration  period,
Coordination  cn 
) -> decltype(rxs::interval(initial, period, std::move(cn)))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::iterate ( Collection  c) -> decltype(rxs::iterate(std::move(c), identity_current_thread()))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::iterate ( Collection  c,
Coordination  cn 
) -> decltype(rxs::iterate(std::move(c), std::move(cn)))
inlinestatic

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 T >
static auto rxcpp::observable< void, void >::just ( v) -> decltype(rxs::just(std::move(v)))
inlinestatic

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 T , class Coordination >
static auto rxcpp::observable< void, void >::just ( v,
Coordination  cn 
) -> decltype(rxs::just(std::move(v), std::move(cn)))
inlinestatic

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 >
static auto rxcpp::observable< void, void >::never ( ) -> decltype(rxs::never<T>())
inlinestatic

template<class T >
static auto rxcpp::observable< void, void >::range ( first = 0,
last = std::numeric_limits<T>::max(),
std::ptrdiff_t  step = 1 
) -> decltype(rxs::range<T>(first, last, step, identity_current_thread()))
inlinestatic

Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler.

Template Parameters
Tthe type of the values that this observable emits
Coordinationthe type of the scheduler (optional)
Parameters
firstfirst value to send (optional)
lastlast value to send (optional)
stepvalue to add to the previous value to get the next value (optional)
cnthe scheduler to run the generator loop on (optional)
Returns
Observable that sends values in the range first-last by adding step to the previous value using the specified scheduler.
Sample Code
printf("[thread %s] Start task\n", get_pid().c_str());
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
An alternative way to specify the scheduler for emitted values is to use observable::subscribe_on operator
printf("[thread %s] Start task\n", get_pid().c_str());
auto values = rxcpp::observable<>::range(1, 3);
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
template<class T , class Coordination >
static auto rxcpp::observable< void, void >::range ( first,
last,
std::ptrdiff_t  step,
Coordination  cn 
) -> decltype(rxs::range<T>(first, last, step, std::move(cn)))
inlinestatic

Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler.

Template Parameters
Tthe type of the values that this observable emits
Coordinationthe type of the scheduler (optional)
Parameters
firstfirst value to send (optional)
lastlast value to send (optional)
stepvalue to add to the previous value to get the next value (optional)
cnthe scheduler to run the generator loop on (optional)
Returns
Observable that sends values in the range first-last by adding step to the previous value using the specified scheduler.
Sample Code
printf("[thread %s] Start task\n", get_pid().c_str());
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
An alternative way to specify the scheduler for emitted values is to use observable::subscribe_on operator
printf("[thread %s] Start task\n", get_pid().c_str());
auto values = rxcpp::observable<>::range(1, 3);
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
template<class T , class Coordination >
static auto rxcpp::observable< void, void >::range ( first,
last,
Coordination  cn 
) -> decltype(rxs::range<T>(first, last, std::move(cn)))
inlinestatic

Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler.

Template Parameters
Tthe type of the values that this observable emits
Coordinationthe type of the scheduler (optional)
Parameters
firstfirst value to send (optional)
lastlast value to send (optional)
stepvalue to add to the previous value to get the next value (optional)
cnthe scheduler to run the generator loop on (optional)
Returns
Observable that sends values in the range first-last by adding step to the previous value using the specified scheduler.
Sample Code
printf("[thread %s] Start task\n", get_pid().c_str());
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
An alternative way to specify the scheduler for emitted values is to use observable::subscribe_on operator
printf("[thread %s] Start task\n", get_pid().c_str());
auto values = rxcpp::observable<>::range(1, 3);
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
template<class T , class Coordination >
static auto rxcpp::observable< void, void >::range ( first,
Coordination  cn 
) -> decltype(rxs::range<T>(first, std::move(cn)))
inlinestatic

Returns an observable that sends values in the range first-last by adding step to the previous value. The values are sent on the specified scheduler.

Template Parameters
Tthe type of the values that this observable emits
Coordinationthe type of the scheduler (optional)
Parameters
firstfirst value to send (optional)
lastlast value to send (optional)
stepvalue to add to the previous value to get the next value (optional)
cnthe scheduler to run the generator loop on (optional)
Returns
Observable that sends values in the range first-last by adding step to the previous value using the specified scheduler.
Sample Code
printf("[thread %s] Start task\n", get_pid().c_str());
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
An alternative way to specify the scheduler for emitted values is to use observable::subscribe_on operator
printf("[thread %s] Start task\n", get_pid().c_str());
auto values = rxcpp::observable<>::range(1, 3);
auto s = values.
map([](int v) { return std::make_tuple(get_pid(), v);});
s.
[](const std::string pid, int v) {
printf("[thread %s] OnNext: %d\n", 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] OnNext: 1
[thread 47481303181056] OnNext: 2
[thread 47481303181056] OnNext: 3
[thread 47481303181056] OnCompleted
[thread 47481267428736] Finish task
template<class ResourceFactory , class ObservableFactory >
static auto rxcpp::observable< void, void >::scope ( ResourceFactory  rf,
ObservableFactory  of 
) -> decltype(rxs::scope(std::move(rf), std::move(of)))
inlinestatic

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>
static auto rxcpp::observable< void, void >::start_with ( Observable  o,
Value0  v0,
ValueN...  vn 
) -> decltype(rxs::start_with(std::move(o), std::move(v0), std::move(vn)...))
inlinestatic

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... AN>
static auto rxcpp::observable< void, void >::timer ( rxsc::scheduler::clock_type::time_point  at,
AN **  ... 
) -> decltype(rxs::timer(at))
inlinestatic

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... AN>
static auto rxcpp::observable< void, void >::timer ( rxsc::scheduler::clock_type::duration  after,
AN **  ... 
) -> decltype(rxs::timer(after))
inlinestatic

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 Coordination >
static auto rxcpp::observable< void, void >::timer ( rxsc::scheduler::clock_type::time_point  when,
Coordination  cn 
) -> decltype(rxs::timer(when, std::move(cn)))
inlinestatic

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 Coordination >
static auto rxcpp::observable< void, void >::timer ( rxsc::scheduler::clock_type::duration  when,
Coordination  cn 
) -> decltype(rxs::timer(when, std::move(cn)))
inlinestatic

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

The documentation for this class was generated from the following file: