// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #pragma once /*! \file rx-replay.hpp \brief 1) replay(optional Coordination, optional CompositeSubscription) Turn a cold observable hot, send all earlier emitted values to any new subscriber, and allow connections to the source to be independent of subscriptions. 2) replay(Count, optional Coordination, optional CompositeSubscription) Turn a cold observable hot, send at most count of earlier emitted values to any new subscriber, and allow connections to the source to be independent of subscriptions. 3) replay(Duration, optional Coordination, optional CompositeSubscription) Turn a cold observable hot, send values emitted within a specified time window to any new subscriber, and allow connections to the source to be independent of subscriptions. 4) replay(Count, Duration, optional Coordination, optional CompositeSubscription) Turn a cold observable hot, send at most count of values emitted within a specified time window to any new subscriber, and allow connections to the source to be independent of subscriptions. \tparam Duration the type of the time interval (optional). \tparam Count the type of the maximum number of the most recent items sent to new observers (optional). \tparam Coordination the type of the scheduler (optional). \param count the maximum number of the most recent items sent to new observers (optional). \param d the duration of the window in which the replayed items must be emitted \param cn a scheduler all values are queued and delivered on (optional). \param cs the subscription to control lifetime (optional). \return rxcpp::connectable_observable that shares a single subscription to the underlying observable that will replay all of its items and notifications to any future observer. \sample \snippet replay.cpp replay sample \snippet output.txt replay sample \sample \snippet replay.cpp threaded replay sample \snippet output.txt threaded replay sample \sample \snippet replay.cpp replay count sample \snippet output.txt replay count sample \sample \snippet replay.cpp threaded replay count sample \snippet output.txt threaded replay count sample \sample \snippet replay.cpp replay period sample \snippet output.txt replay period sample \sample \snippet replay.cpp threaded replay period sample \snippet output.txt threaded replay period sample \sample \snippet replay.cpp replay count+period sample \snippet output.txt replay count+period sample \sample \snippet replay.cpp threaded replay count+period sample \snippet output.txt threaded replay count+period sample */ #if !defined(RXCPP_OPERATORS_RX_REPLAY_HPP) #define RXCPP_OPERATORS_RX_REPLAY_HPP #include "../rx-includes.hpp" #include "./rx-multicast.hpp" namespace rxcpp { namespace operators { namespace detail { template struct replay_invalid_arguments {}; template struct replay_invalid : public rxo::operator_base> { using type = observable, replay_invalid>; }; template using replay_invalid_t = typename replay_invalid::type; } /*! @copydoc rx-replay.hpp */ template auto replay(AN&&... an) -> operator_factory { return operator_factory(std::make_tuple(std::forward(an)...)); } } template<> struct member_overload { template>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o) { return Result(Multicast(std::forward(o), Subject(identity_current_thread(), composite_subscription()))); } template>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, composite_subscription cs) { return Result(Multicast(std::forward(o), Subject(identity_current_thread(), cs))); } template, is_coordination>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay>, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Coordination&& cn, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(std::forward(cn), cs))); } template, std::is_integral>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Count count, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(count, identity_current_thread(), cs))); } template, std::is_integral, is_coordination>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay>, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Count count, Coordination&& cn, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(count, std::forward(cn), cs))); } template, class Enabled = rxu::enable_if_all_true_type_t< is_observable, IsDuration>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Duration&& d, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(std::forward(d), identity_current_thread(), cs))); } template, class Enabled = rxu::enable_if_all_true_type_t< is_observable, IsDuration, is_coordination>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay>, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Duration&& d, Coordination&& cn, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(std::forward(d), std::forward(cn), cs))); } template, class Enabled = rxu::enable_if_all_true_type_t< is_observable, std::is_integral, IsDuration>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Count count, Duration&& d, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(count, std::forward(d), identity_current_thread(), cs))); } template, class Enabled = rxu::enable_if_all_true_type_t< is_observable, std::is_integral, IsDuration, is_coordination>, class SourceValue = rxu::value_type_t, class Subject = rxsub::replay>, class Multicast = rxo::detail::multicast, Subject>, class Result = connectable_observable > static Result member(Observable&& o, Count count, Duration&& d, Coordination&& cn, composite_subscription cs = composite_subscription()) { return Result(Multicast(std::forward(o), Subject(count, std::forward(d), std::forward(cn), cs))); } template static operators::detail::replay_invalid_t member(AN...) { std::terminate(); return {}; static_assert(sizeof...(AN) == 10000, "replay takes (optional Count, optional Duration, optional Coordination, optional CompositeSubscription)"); } }; } #endif