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++.
Namespaces | Macros | Functions
rx-subscribe.hpp File Reference

Subscribe will cause the source observable to emit values to the provided subscriber. More...

#include "../rx-includes.hpp"
Include dependency graph for rx-subscribe.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 rxcpp
 
 rxcpp::operators
 

Macros

#define RXCPP_OPERATORS_RX_SUBSCRIBE_HPP
 

Functions

template<class T , class... ArgN>
auto rxcpp::operators::subscribe (ArgN &&... an) -> detail::subscribe_factory< decltype(make_subscriber< T >(std::forward< ArgN >(an)...))>
 
auto rxcpp::operators::as_dynamic () -> detail::dynamic_factory
 
auto rxcpp::operators::as_blocking () -> detail::blocking_factory
 

Detailed Description

Subscribe will cause the source observable to emit values to the provided subscriber.

Template Parameters
ArgNtypes of the subscriber parameters
Parameters
anthe parameters for making a subscriber
Returns
A subscription with which the observer can stop receiving items before the observable has finished sending them.

The arguments of subscribe are forwarded to rxcpp::make_subscriber function. Some possible alternatives are:

All the alternatives above also support passing rxcpp::composite_subscription instance. For example:

auto subscription = rxcpp::composite_subscription();
auto values = rxcpp::observable<>::range(1, 5);
values.subscribe(
subscription,
[&subscription](int v){
printf("OnNext: %d\n", v);
if (v == 3)
subscription.unsubscribe();
},
[](){printf("OnCompleted\n");});
OnNext: 1
OnNext: 2
OnNext: 3

If neither subscription nor subscriber are provided, then a new subscription is created and returned as a result:

auto values = rxcpp::observable<>::range(1, 3).
finally([](){printf("The final action\n");});
auto subscription = values.subscribe(
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
subscription.unsubscribe();
OnNext: 1
OnNext: 2
OnNext: 3
The final action

For more details, see rxcpp::make_subscriber function description.

Macro Definition Documentation

◆ RXCPP_OPERATORS_RX_SUBSCRIBE_HPP

#define RXCPP_OPERATORS_RX_SUBSCRIBE_HPP
rxcpp::operators::concat
auto concat(AN &&... an) -> operator_factory< concat_tag, AN... >
Definition: rx-concat.hpp:235
rxcpp::sources::range
auto range(T first=0, T last=std::numeric_limits< T >::max(), std::ptrdiff_t step=1) -> observable< T, detail::range< T, identity_one_worker >>
Definition: rx-range.hpp:119
cpplinq::from
linq_driver< iter_cursor< typename util::container_traits< TContainer >::iterator > > from(TContainer &c)
Definition: linq.hpp:556
rxcpp::util::rethrow_exception
RXCPP_NORETURN void rethrow_exception(error_ptr e)
Definition: rx-util.hpp:902
rxcpp::composite_subscription
controls lifetime for scheduler::schedule and observable<T, SourceOperator>::subscribe.
Definition: rx-subscription.hpp:459
rxcpp::observable
a source of values. subscribe or use one of the operator methods that return a new observable,...
Definition: rx-observable.hpp:478