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

Turn a cold observable hot and allow connections to the source to be independent of subscriptions. Turn a cold observable hot, send the most recent value to any new subscriber, and allow connections to the source to be independent of subscriptions. More...

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

Go to the source code of this file.

Classes

struct  rxcpp::member_overload< publish_tag >
 
struct  rxcpp::member_overload< publish_synchronized_tag >
 

Namespaces

 rxcpp
 
 rxcpp::operators
 

Macros

#define RXCPP_OPERATORS_RX_PUBLISH_HPP
 

Functions

template<class... AN>
auto rxcpp::operators::publish (AN &&...an) -> operator_factory< publish_tag, AN... >
 Turn a cold observable hot and allow connections to the source to be independent of subscriptions. Turn a cold observable hot, send the most recent value to any new subscriber, and allow connections to the source to be independent of subscriptions. More...
 
template<class... AN>
auto rxcpp::operators::publish_synchronized (AN &&...an) -> operator_factory< publish_synchronized_tag, AN... >
 Turn a cold observable hot and allow connections to the source to be independent of subscriptions. More...
 

Detailed Description

Turn a cold observable hot and allow connections to the source to be independent of subscriptions. Turn a cold observable hot, send the most recent value to any new subscriber, and allow connections to the source to be independent of subscriptions.

Template Parameters
Tthe type of the emitted item (optional).
Parameters
firstan initial item to be emitted by the resulting observable at connection time before emitting the items from the source observable; not emitted to observers that subscribe after the time of connection (optional).
csthe subscription to control lifetime (optional).
Returns
rxcpp::connectable_observable that upon connection causes the source observable to emit items to its observers.
Sample Code
auto values = rxcpp::observable<>::interval(std::chrono::milliseconds(50), rxcpp::observe_on_new_thread()).
take(5).
// Subscribe from the beginning
values.subscribe(
[](long v){printf("[1] OnNext: %ld\n", v);},
[](){printf("[1] OnCompleted\n");});
// Another subscription from the beginning
values.subscribe(
[](long v){printf("[2] OnNext: %ld\n", v);},
[](){printf("[2] OnCompleted\n");});
// Start emitting
values.connect();
// Wait before subscribing
rxcpp::observable<>::timer(std::chrono::milliseconds(75)).subscribe([&](long){
values.subscribe(
[](long v){printf("[3] OnNext: %ld\n", v);},
[](){printf("[3] OnCompleted\n");});
});
// Add blocking subscription to see results
values.as_blocking().subscribe();
[1] OnNext: 1
[2] OnNext: 1
[1] OnNext: 2
[2] OnNext: 2
[1] OnNext: 3
[2] OnNext: 3
[3] OnNext: 3
[1] OnNext: 4
[2] OnNext: 4
[3] OnNext: 4
[1] OnNext: 5
[2] OnNext: 5
[3] OnNext: 5
[1] OnCompleted
[2] OnCompleted
[3] OnCompleted
Sample Code
auto values = rxcpp::observable<>::interval(std::chrono::milliseconds(50), rxcpp::observe_on_new_thread()).
take(5).
publish(0L);
// Subscribe from the beginning
values.subscribe(
[](long v){printf("[1] OnNext: %ld\n", v);},
[](){printf("[1] OnCompleted\n");});
// Another subscription from the beginning
values.subscribe(
[](long v){printf("[2] OnNext: %ld\n", v);},
[](){printf("[2] OnCompleted\n");});
// Start emitting
values.connect();
// Wait before subscribing
rxcpp::observable<>::timer(std::chrono::milliseconds(75)).subscribe([&](long){
values.subscribe(
[](long v){printf("[3] OnNext: %ld\n", v);},
[](){printf("[3] OnCompleted\n");});
});
// Add blocking subscription to see results
values.as_blocking().subscribe();
[1] OnNext: 0
[2] OnNext: 0
[1] OnNext: 1
[2] OnNext: 1
[1] OnNext: 2
[2] OnNext: 2
[3] OnNext: 2
[1] OnNext: 3
[2] OnNext: 3
[3] OnNext: 3
[1] OnNext: 4
[2] OnNext: 4
[3] OnNext: 4
[1] OnNext: 5
[2] OnNext: 5
[3] OnNext: 5
[1] OnCompleted
[2] OnCompleted
[3] OnCompleted

Macro Definition Documentation

#define RXCPP_OPERATORS_RX_PUBLISH_HPP