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)...))>
 Subscribe will cause the source observable to emit values to the provided subscriber. More...
 
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

#define RXCPP_OPERATORS_RX_SUBSCRIBE_HPP