// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System.Reactive.Concurrency; using System.Reactive.Subjects; namespace System.Reactive.Linq { public static partial class Observable { #region + Multicast + /// /// Multicasts the source sequence notifications through the specified subject to the resulting connectable observable. Upon connection of the /// connectable observable, the subject is subscribed to the source exactly one, and messages are forwarded to the observers registered with /// the connectable observable. For specializations with fixed subject types, see Publish, PublishLast, and Replay. /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be pushed into the specified subject. /// Subject to push source elements into. /// A connectable observable sequence that upon connection causes the source sequence to push results into the specified subject. /// or is null. public static IConnectableObservable Multicast(this IObservable source, ISubject subject) { if (source == null) throw new ArgumentNullException("source"); if (subject == null) throw new ArgumentNullException("subject"); return s_impl.Multicast(source, subject); } /// /// Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function. Each /// subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function's /// invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay. /// /// The type of the elements in the source sequence. /// The type of the elements produced by the intermediate subject. /// The type of the elements in the result sequence. /// Source sequence which will be multicasted in the specified selector function. /// Factory function to create an intermediate subject through which the source sequence's elements will be multicast to the selector function. /// Selector function which can use the multicasted source sequence subject to the policies enforced by the created subject. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or or is null. public static IObservable Multicast(this IObservable source, Func> subjectSelector, Func, IObservable> selector) { if (source == null) throw new ArgumentNullException("source"); if (subjectSelector == null) throw new ArgumentNullException("subjectSelector"); if (selector == null) throw new ArgumentNullException("selector"); return s_impl.Multicast(source, subjectSelector, selector); } #endregion #region + Publish + /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence. /// This operator is a specialization of Multicast using a regular . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// Subscribers will receive all notifications of the source from the time of the subscription on. /// public static IConnectableObservable Publish(this IObservable source) { if (source == null) throw new ArgumentNullException("source"); return s_impl.Publish(source); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence. /// This operator is a specialization of Multicast using a regular . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// public static IObservable Publish(this IObservable source, Func, IObservable> selector) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); return s_impl.Publish(source, selector); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Initial value received by observers upon subscription. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// Subscribers will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. /// public static IConnectableObservable Publish(this IObservable source, TSource initialValue) { if (source == null) throw new ArgumentNullException("source"); return s_impl.Publish(source, initialValue); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initialValue. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on. /// Initial value received by observers upon subscription. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// public static IObservable Publish(this IObservable source, Func, IObservable> selector, TSource initialValue) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); return s_impl.Publish(source, selector, initialValue); } #endregion #region + PublishLast + /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// Subscribers will only receive the last notification of the source. /// public static IConnectableObservable PublishLast(this IObservable source) { if (source == null) throw new ArgumentNullException("source"); return s_impl.PublishLast(source); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence containing only the last notification. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will only receive the last notification of the source. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// public static IObservable PublishLast(this IObservable source, Func, IObservable> selector) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); return s_impl.PublishLast(source, selector); } #endregion #region + RefCount + /// /// Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence. /// /// The type of the elements in the source sequence. /// Connectable observable sequence. /// An observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence. /// is null. public static IObservable RefCount(this IConnectableObservable source) { if (source == null) throw new ArgumentNullException("source"); return s_impl.RefCount(source); } #endregion #region + Replay + /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// Subscribers will receive all the notifications of the source. /// public static IConnectableObservable Replay(this IObservable source) { if (source == null) throw new ArgumentNullException("source"); return s_impl.Replay(source); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Scheduler where connected observers will be invoked on. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// or is null. /// Subscribers will receive all the notifications of the source. /// public static IConnectableObservable Replay(this IObservable source, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, scheduler); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); return s_impl.Replay(source, selector); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source. /// Scheduler where connected observers within the selector function will be invoked on. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or or is null. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, selector, scheduler); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Maximum time length of the replay buffer. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// is less than TimeSpan.Zero. /// Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// public static IConnectableObservable Replay(this IObservable source, TimeSpan window) { if (source == null) throw new ArgumentNullException("source"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); return s_impl.Replay(source, window); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// Maximum time length of the replay buffer. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// is less than TimeSpan.Zero. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, TimeSpan window) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); return s_impl.Replay(source, selector, window); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Maximum time length of the replay buffer. /// Scheduler where connected observers will be invoked on. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// or is null. /// is less than TimeSpan.Zero. /// Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// public static IConnectableObservable Replay(this IObservable source, TimeSpan window, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, window, scheduler); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// Maximum time length of the replay buffer. /// Scheduler where connected observers within the selector function will be invoked on. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or or is null. /// is less than TimeSpan.Zero. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, TimeSpan window, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, selector, window, scheduler); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying bufferSize notifications. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Maximum element count of the replay buffer. /// Scheduler where connected observers will be invoked on. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// or is null. /// is less than zero. /// Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// public static IConnectableObservable Replay(this IObservable source, int bufferSize, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, bufferSize, scheduler); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// Maximum element count of the replay buffer. /// Scheduler where connected observers within the selector function will be invoked on. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or or is null. /// is less than zero. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, int bufferSize, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, selector, bufferSize, scheduler); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Maximum element count of the replay buffer. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// is less than zero. /// Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// public static IConnectableObservable Replay(this IObservable source, int bufferSize) { if (source == null) throw new ArgumentNullException("source"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); return s_impl.Replay(source, bufferSize); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// Maximum element count of the replay buffer. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// is less than zero. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, int bufferSize) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); return s_impl.Replay(source, selector, bufferSize); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Maximum element count of the replay buffer. /// Maximum time length of the replay buffer. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// is null. /// is less than zero. /// is less than TimeSpan.Zero. /// Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// public static IConnectableObservable Replay(this IObservable source, int bufferSize, TimeSpan window) { if (source == null) throw new ArgumentNullException("source"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); return s_impl.Replay(source, bufferSize, window); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// Maximum element count of the replay buffer. /// Maximum time length of the replay buffer. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or is null. /// is less than zero. /// is less than TimeSpan.Zero. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, int bufferSize, TimeSpan window) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); return s_impl.Replay(source, selector, bufferSize, window); } /// /// Returns a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Maximum element count of the replay buffer. /// Maximum time length of the replay buffer. /// Scheduler where connected observers will be invoked on. /// A connectable observable sequence that shares a single subscription to the underlying sequence. /// or is null. /// is less than zero. /// is less than TimeSpan.Zero. /// Subscribers will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// public static IConnectableObservable Replay(this IObservable source, int bufferSize, TimeSpan window, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, bufferSize, window, scheduler); } /// /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length and element count for the replay buffer. /// This operator is a specialization of Multicast using a . /// /// The type of the elements in the source sequence. /// The type of the elements in the result sequence. /// Source sequence whose elements will be multicasted through a single shared subscription. /// Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy. /// Maximum element count of the replay buffer. /// Maximum time length of the replay buffer. /// Scheduler where connected observers within the selector function will be invoked on. /// An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function. /// or or is null. /// is less than zero. /// is less than TimeSpan.Zero. /// public static IObservable Replay(this IObservable source, Func, IObservable> selector, int bufferSize, TimeSpan window, IScheduler scheduler) { if (source == null) throw new ArgumentNullException("source"); if (selector == null) throw new ArgumentNullException("selector"); if (bufferSize < 0) throw new ArgumentOutOfRangeException("bufferSize"); if (window < TimeSpan.Zero) throw new ArgumentOutOfRangeException("window"); if (scheduler == null) throw new ArgumentNullException("scheduler"); return s_impl.Replay(source, selector, bufferSize, window, scheduler); } #endregion } }