summaryrefslogtreecommitdiff
path: root/Rx/v2/src/rxcpp/rx-observable.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Rx/v2/src/rxcpp/rx-observable.hpp')
-rw-r--r--Rx/v2/src/rxcpp/rx-observable.hpp480
1 files changed, 77 insertions, 403 deletions
diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp
index 3db90ab..6ad8da7 100644
--- a/Rx/v2/src/rxcpp/rx-observable.hpp
+++ b/Rx/v2/src/rxcpp/rx-observable.hpp
@@ -598,30 +598,16 @@ public:
}
#endif
- /*! Return a new observable that performs type-forgetting conversion of this observable.
-
- \return The source observable converted to observable<T>.
-
- \note This operator could be useful to workaround lambda deduction bug on msvc 2013.
-
- \sample
- \snippet as_dynamic.cpp as_dynamic sample
- \snippet output.txt as_dynamic sample
- */
+ /*! @copydoc rxcpp::operators::as_dynamic
+ */
template<class... AN>
observable<T> as_dynamic(AN**...) const {
return *this;
static_assert(sizeof...(AN) == 0, "as_dynamic() was passed too many arguments.");
}
- /*! Return a new observable that contains the blocking methods for this observable.
-
- \return An observable that contains the blocking methods for this observable.
-
- \sample
- \snippet from.cpp threaded from sample
- \snippet output.txt threaded from sample
- */
+ /*! @copydoc rxcpp::operators::as_blocking
+ */
template<class... AN>
blocking_observable<T, this_type> as_blocking(AN**...) const {
return blocking_observable<T, this_type>(*this);
@@ -1571,535 +1557,223 @@ class observable<void, void>
{
~observable();
public:
- /*! Returns an observable that executes the specified function when a subscriber subscribes to it.
-
- \tparam T the type of the items that this observable emits
- \tparam OnSubscribe the type of OnSubscribe handler function
-
- \param os OnSubscribe event handler
-
- \return Observable that executes the specified function when a Subscriber subscribes to it.
-
- \sample
- \snippet create.cpp Create sample
- \snippet output.txt Create sample
-
- \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.
-
- \badcode
- \snippet create.cpp Create bad code
- \snippet output.txt Create bad code
-
- \goodcode
- \snippet create.cpp Create good code
- \snippet output.txt Create good code
-
- \warning
- It is good practice to use operators like observable::take to control lifetime rather than use the subscription explicitly.
-
- \goodcode
- \snippet create.cpp Create great code
- \snippet output.txt Create great code
- */
+ /*! @copydoc rx-create.hpp
+ */
template<class T, class OnSubscribe>
static auto create(OnSubscribe os)
-> decltype(rxs::create<T>(std::move(os))) {
return rxs::create<T>(std::move(os));
}
- /*! Returns an observable that sends values in the range first-last by adding step to the previous value.
-
- \tparam T the type of the values that this observable emits
- \param first first value to send
- \param last last value to send
- \param step value to add to the previous value to get the next value
-
- \return Observable that sends values in the range first-last by adding step to the previous value.
-
- \sample
- \snippet range.cpp range sample
- \snippet output.txt range sample
- */
+ /*! @copydoc rx-range.hpp
+ */
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())) {
return 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.
-
- \tparam T the type of the values that this observable emits
- \tparam Coordination the type of the scheduler
-
- \param first first value to send
- \param last last value to send
- \param step value to add to the previous value to get the next value
- \param cn the scheduler to run the generator loop on
-
- \return Observable that sends values in the range first-last by adding step to the previous value using the specified scheduler.
-
- \note `step` or both `step` & `last` may be omitted.
-
- \sample
- \snippet range.cpp threaded range sample
- \snippet output.txt threaded range sample
-
- An alternative way to specify the scheduler for emitted values is to use observable::subscribe_on operator
- \snippet range.cpp subscribe_on range sample
- \snippet output.txt subscribe_on range sample
- */
+ /*! @copydoc rx-range.hpp
+ */
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))) {
return rxs::range<T>(first, last, step, std::move(cn));
}
- /// Returns an observable that sends values in the range ```first```-```last``` by adding 1 to the previous value. The values are sent on the specified scheduler.
- ///
- /// \see rxcpp::observable<void,void>#range(T first, T last, std::ptrdiff_t step, Coordination cn)
+ /*! @copydoc rx-range.hpp
+ */
template<class T, class Coordination>
static auto range(T first, T last, Coordination cn)
-> decltype(rxs::range<T>(first, last, std::move(cn))) {
return rxs::range<T>(first, last, std::move(cn));
}
- /// Returns an observable that infinitely (until overflow) sends values starting from ```first```. The values are sent on the specified scheduler.
- ///
- /// \see rxcpp::observable<void,void>#range(T first, T last, std::ptrdiff_t step, Coordination cn)
+ /*! @copydoc rx-range.hpp
+ */
template<class T, class Coordination>
static auto range(T first, Coordination cn)
-> decltype(rxs::range<T>(first, std::move(cn))) {
return rxs::range<T>(first, std::move(cn));
}
- /*! Returns an observable that never sends any items or notifications to observer.
-
- \tparam T the type of (not) emitted items
-
- \return Observable that never sends any items or notifications to observer.
- \sample
- \snippet never.cpp never sample
- \snippet output.txt never sample
- */
+ /*! @copydoc rx-never.hpp
+ */
template<class T>
static auto never()
-> decltype(rxs::never<T>()) {
return rxs::never<T>();
}
- /*! Returns an observable that calls the specified observable factory to create an observable for each new observer that subscribes.
- \tparam ObservableFactory the type of the observable factory
-
- \param of the observable factory function to invoke for each observer that subscribes to the resulting observable
-
- \return observable whose observers' subscriptions trigger an invocation of the given observable factory function
-
- \sample
- \snippet defer.cpp defer sample
- \snippet output.txt defer sample
- */
+ /*! @copydoc rx-defer.hpp
+ */
template<class ObservableFactory>
static auto defer(ObservableFactory of)
-> decltype(rxs::defer(std::move(of))) {
return rxs::defer(std::move(of));
}
- /*! Returns an observable that emits a sequential integer every specified time interval.
- \param period period between emitted values
-
- \return Observable that sends a sequential integer each time interval
-
- \sample
- \snippet interval.cpp immediate interval sample
- \snippet output.txt immediate interval sample
- */
+ /*! @copydoc rx-interval.hpp
+ */
template<class... AN>
static auto interval(rxsc::scheduler::clock_type::duration period, AN**...)
-> decltype(rxs::interval(period)) {
return rxs::interval(period);
static_assert(sizeof...(AN) == 0, "interval(period) was passed too many arguments.");
}
- /*! Returns an observable that emits a sequential integer every specified time interval, on the specified scheduler.
-
- \tparam Coordination the type of the scheduler
-
- \param period period between emitted values
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that sends a sequential integer each time interval
-
- \sample
- \snippet interval.cpp threaded immediate interval sample
- \snippet output.txt threaded immediate interval sample
- */
+ /*! @copydoc rx-interval.hpp
+ */
template<class Coordination>
static auto interval(rxsc::scheduler::clock_type::duration period, Coordination cn)
-> decltype(rxs::interval(period, std::move(cn))) {
return rxs::interval(period, std::move(cn));
}
- /*! Returns an observable that emits a sequential integer every specified time interval starting from the specified time point.
-
- \param initial time when the first value is sent
- \param period period between emitted values
-
- \return Observable that sends a sequential integer each time interval
-
- \sample
- \snippet interval.cpp interval sample
- \snippet output.txt interval sample
- */
+ /*! @copydoc rx-interval.hpp
+ */
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)) {
return rxs::interval(initial, period);
static_assert(sizeof...(AN) == 0, "interval(initial, period) was passed too many arguments.");
}
- /*! Returns an observable that emits a sequential integer every specified time interval starting from the specified time point, on the specified scheduler.
-
- \tparam Coordination the type of the scheduler
-
- \param initial time when the first value is sent
- \param period period between emitted values
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that sends a sequential integer each time interval
-
- \sample
- \snippet interval.cpp threaded interval sample
- \snippet output.txt threaded interval sample
- */
+ /*! @copydoc rx-interval.hpp
+ */
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))) {
return rxs::interval(initial, period, std::move(cn));
}
- /*! Returns an observable that emits an integer at the specified time point.
-
- \param when time point when the value is emitted
-
- \return Observable that emits an integer at the specified time point
- \sample
- \snippet timer.cpp timepoint timer sample
- \snippet output.txt timepoint timer sample
- */
+ /*! @copydoc rx-timer.hpp
+ */
template<class... AN>
static auto timer(rxsc::scheduler::clock_type::time_point at, AN**...)
-> decltype(rxs::timer(at)) {
return rxs::timer(at);
static_assert(sizeof...(AN) == 0, "timer(at) was passed too many arguments.");
}
- /*! Returns an observable that emits an integer in the specified time interval.
-
- \param when interval when the value is emitted
-
- \return Observable that emits an integer in the specified time interval
-
- \sample
- \snippet timer.cpp duration timer sample
- \snippet output.txt duration timer sample
- */
+ /*! @copydoc rx-timer.hpp
+ */
template<class... AN>
static auto timer(rxsc::scheduler::clock_type::duration after, AN**...)
-> decltype(rxs::timer(after)) {
return rxs::timer(after);
static_assert(sizeof...(AN) == 0, "timer(after) was passed too many arguments.");
}
- /*! Returns an observable that emits an integer at the specified time point, on the specified scheduler.
-
- \tparam Coordination the type of the scheduler
-
- \param when time point when the value is emitted
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that emits an integer at the specified time point
-
- \sample
- \snippet timer.cpp threaded timepoint timer sample
- \snippet output.txt threaded timepoint timer sample
- */
+ /*! @copydoc rx-timer.hpp
+ */
template<class Coordination>
static auto timer(rxsc::scheduler::clock_type::time_point when, Coordination cn)
-> decltype(rxs::timer(when, std::move(cn))) {
return rxs::timer(when, std::move(cn));
}
- /*! Returns an observable that emits an integer in the specified time interval, on the specified scheduler.
-
- \tparam Coordination the type of the scheduler
-
- \param when interval when the value is emitted
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that emits an integer in the specified time interval
-
- \sample
- \snippet timer.cpp threaded duration timer sample
- \snippet output.txt threaded duration timer sample
- */
+ /*! @copydoc rx-timer.hpp
+ */
template<class Coordination>
static auto timer(rxsc::scheduler::clock_type::duration when, Coordination cn)
-> decltype(rxs::timer(when, std::move(cn))) {
return rxs::timer(when, std::move(cn));
}
- /*! Returns an observable that sends each value in the collection.
-
- \tparam Collection the type of the collection of values that this observable emits
-
- \param c collection containing values to send
-
- \return Observable that sends each value in the collection.
- \sample
- \snippet iterate.cpp iterate sample
- \snippet output.txt iterate sample
- */
+ /*! @copydoc rx-iterate.hpp
+ */
template<class Collection>
static auto iterate(Collection c)
-> decltype(rxs::iterate(std::move(c), identity_current_thread())) {
return rxs::iterate(std::move(c), identity_current_thread());
}
- /*! Returns an observable that sends each value in the collection, on the specified scheduler.
-
- \tparam Collection the type of the collection of values that this observable emits
- \tparam Coordination the type of the scheduler
-
- \param c collection containing values to send
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that sends each value in the collection.
-
- \sample
- \snippet iterate.cpp threaded iterate sample
- \snippet output.txt threaded iterate sample
- */
+ /*! @copydoc rx-iterate.hpp
+ */
template<class Collection, class Coordination>
static auto iterate(Collection c, Coordination cn)
-> decltype(rxs::iterate(std::move(c), std::move(cn))) {
return rxs::iterate(std::move(c), std::move(cn));
}
- /*! Returns an observable that sends an empty set of values and then completes.
-
- \tparam T the type of elements (not) to be sent
- \return 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 ```observable<void,void>::from(Value0 v0, ValueN... vn)``` operator.
- */
+ /*! @copydoc rxcpp::sources::from()
+ */
template<class T>
static auto from()
-> decltype( rxs::from<T>()) {
return rxs::from<T>();
}
- /*! Returns an observable that sends an empty set of values and then completes, on the specified scheduler.
-
- \tparam T the type of elements (not) to be sent
- \tparam Coordination the type of the scheduler
-
- \return Observable that sends an empty set of values and then completes.
-
- \note This is a degenerate case of ```observable<void,void>::from(Coordination cn, Value0 v0, ValueN... vn)``` operator.
- */
+ /*! @copydoc rxcpp::sources::from(Coordination cn)
+ */
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 {
return rxs::from<T>(std::move(cn));
}
- /*! Returns an observable that sends each value from its arguments list.
-
- \tparam Value0 ...
- \tparam ValueN the type of sending values
-
- \param v0 ...
- \param vn values to send
-
- \return Observable that sends each value from its arguments list.
-
- \sample
- \snippet from.cpp from sample
- \snippet output.txt from sample
-
- \note This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.
- */
+ /*! @copydoc rxcpp::sources::from(Value0 v0, ValueN... vn)
+ */
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 {
return rxs::from(v0, vn...);
}
- /*! Returns an observable that sends each value from its arguments list, on the specified scheduler.
-
- \tparam Coordination the type of the scheduler
- \tparam Value0 ...
- \tparam ValueN the type of sending values
-
- \param cn the scheduler to use for scheduling the items
- \param v0 ...
- \param vn values to send
-
- \return Observable that sends each value from its arguments list.
-
- \sample
- \snippet from.cpp threaded from sample
- \snippet output.txt threaded from sample
-
- \note This operator is useful to send separated values. If they are stored as a collection, use observable<void,void>::iterate instead.
- */
+ /*! @copydoc rxcpp::sources::from(Coordination cn, Value0 v0, ValueN... vn)
+ */
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 {
return rxs::from(std::move(cn), v0, vn...);
}
- /*! Returns an observable that sends no items to observer and immediately completes.
- \tparam T the type of (not) emitted items
+ /*! @copydoc rxcpp::sources::just(Value0 v0)
+ */
+ template<class T>
+ static auto just(T v)
+ -> decltype(rxs::just(std::move(v))) {
+ return rxs::just(std::move(v));
+ }
+ /*! @copydoc rxcpp::sources::just(Value0 v0, Coordination cn)
+ */
+ template<class T, class Coordination>
+ static auto just(T v, Coordination cn)
+ -> decltype(rxs::just(std::move(v), std::move(cn))) {
+ return rxs::just(std::move(v), std::move(cn));
+ }
- \return Observable that sends no items to observer and immediately completes.
+ /*! @copydoc rxcpp::sources::start_with(Observable o, Value0 v0, ValueN... vn)
+ */
+ 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)...)) {
+ return rxs::start_with(std::move(o), std::move(v0), std::move(vn)...);
+ }
- \sample
- \snippet empty.cpp empty sample
- \snippet output.txt empty sample
- */
+ /*! @copydoc rx-empty.hpp
+ */
template<class T>
static auto empty()
-> decltype(from<T>()) {
return from<T>();
}
- /*! Returns an observable that sends no items to observer and immediately completes, on the specified scheduler.
-
- \tparam T the type of (not) emitted items
- \tparam Coordination the type of the scheduler
-
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that sends no items to observer and immediately completes.
-
- \sample
- \snippet empty.cpp threaded empty sample
- \snippet output.txt threaded empty sample
- */
+ /*! @copydoc rx-empty.hpp
+ */
template<class T, class Coordination>
static auto empty(Coordination cn)
-> decltype(from<T>(std::move(cn))) {
return from<T>(std::move(cn));
}
- /*! Returns an observable that sends the specified item to observer and then completes.
-
- \tparam T the type of the emitted item
-
- \param v the value to send
-
- \return Observable that sends the specified item to observer and then completes.
-
- \sample
- \snippet just.cpp just sample
- \snippet output.txt just sample
- */
- template<class T>
- static auto just(T v)
- -> decltype(from(std::move(v))) {
- return from(std::move(v));
- }
- /*! Returns an observable that sends the specified item to observer and then completes, on the specified scheduler.
-
- \tparam T the type of the emitted item
- \tparam Coordination the type of the scheduler
-
- \param v the value to send
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that sends the specified item to observer and then completes.
-
- \sample
- \snippet just.cpp threaded just sample
- \snippet output.txt threaded just sample
- */
- template<class T, class Coordination>
- static auto just(T v, Coordination cn)
- -> decltype(from(std::move(cn), std::move(v))) {
- return from(std::move(cn), std::move(v));
- }
- /*! Returns an observable that sends no items to observer and immediately generates an error.
-
- \tparam T the type of (not) emitted items
- \tparam Exception the type of the error
-
- \param e the error to be passed to observers
-
- \return Observable that sends no items to observer and immediately generates an error.
- \sample
- \snippet error.cpp error sample
- \snippet output.txt error sample
- */
+ /*! @copydoc rx-error.hpp
+ */
template<class T, class Exception>
static auto error(Exception&& e)
-> decltype(rxs::error<T>(std::forward<Exception>(e))) {
return 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.
-
- \tparam T the type of (not) emitted items
- \tparam Exception the type of the error
- \tparam Coordination the type of the scheduler
-
- \param e the error to be passed to observers
- \param cn the scheduler to use for scheduling the items
-
- \return Observable that sends no items to observer and immediately generates an error.
-
- \sample
- \snippet error.cpp threaded error sample
- \snippet output.txt threaded error sample
- */
+ /*! @copydoc rx-error.hpp
+ */
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))) {
return rxs::error<T>(std::forward<Exception>(e), std::move(cn));
}
- /*! Returns an observable that sends the specified values before it begins to send items emitted by the given observable.
-
- \tparam Observable the type of the observable that emits values for resending
- \tparam Value0 ...
- \tparam ValueN the type of sending values
-
- \param o the observable that emits values for resending
- \param v0 ...
- \param vn values to send
-
- \return Observable that sends the specified values before it begins to send items emitted by the given observable.
-
- \sample
- \snippet start_with.cpp full start_with sample
- \snippet output.txt full start_with sample
-
- Instead of passing the observable as a parameter, you can use rxcpp::observable<T, SourceOperator>::start_with method of the existing observable:
- \snippet start_with.cpp short start_with sample
- \snippet output.txt short start_with sample
- */
- template<class Observable, class Value0, class... ValueN>
- static auto start_with(Observable o, Value0 v0, ValueN... vn)
- -> decltype(rxs::from(rxu::value_type_t<Observable>(v0), rxu::value_type_t<Observable>(vn)...).concat(o)) {
- return rxs::from(rxu::value_type_t<Observable>(v0), rxu::value_type_t<Observable>(vn)...).concat(o);
- }
- /*! 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.
- \tparam ResourceFactory the type of the resource factory
- \tparam ObservableFactory the type of the observable factory
-
- \param rf the resource factory function that resturn the rxcpp::resource that is used as a resource by the observable factory
- \param of the observable factory function to invoke for each observer that subscribes to the resulting observable
-
- \return 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
- \snippet scope.cpp scope sample
- \snippet output.txt scope sample
- */
+ /*! @copydoc rx-scope.hpp
+ */
template<class ResourceFactory, class ObservableFactory>
static auto scope(ResourceFactory rf, ObservableFactory of)
-> decltype(rxs::scope(std::move(rf), std::move(of))) {