Search Results for

    Show / Hide Table of Contents

    Class Observer

    Provides a set of static methods for creating observers.

    Inheritance
    Object
    Observer
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ToString()
    Object.ReferenceEquals(Object, Object)
    Namespace: System.Reactive
    Assembly: System.Reactive.Core.dll
    Syntax
    public static class Observer

    Methods

    | Improve this Doc View Source

    AsObserver<T>(IObserver<T>)

    Hides the identity of an observer.

    Declaration
    public static IObserver<T> AsObserver<T>(this IObserver<T> observer)
    Parameters
    Type Name Description
    IObserver<T> observer

    An observer whose identity to hide.

    Returns
    Type Description
    IObserver<T>

    An observer that hides the identity of the specified observer.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Exceptions
    Type Condition
    ArgumentNullException

    observer is null.

    | Improve this Doc View Source

    Checked<T>(IObserver<T>)

    Checks access to the observer for grammar violations. This includes checking for multiple OnError or OnCompleted calls, as well as reentrancy in any of the observer methods. If a violation is detected, an InvalidOperationException is thrown from the offending observer method call.

    Declaration
    public static IObserver<T> Checked<T>(this IObserver<T> observer)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer whose callback invocations should be checked for grammar violations.

    Returns
    Type Description
    IObserver<T>

    An observer that checks callbacks invocations against the observer grammar and, if the checks pass, forwards those to the specified observer.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Exceptions
    Type Condition
    ArgumentNullException

    observer is null.

    | Improve this Doc View Source

    Create<T>(Action<T>)

    Creates an observer from the specified OnNext action.

    Declaration
    public static IObserver<T> Create<T>(Action<T> onNext)
    Parameters
    Type Name Description
    Action<T> onNext

    Observer's OnNext action implementation.

    Returns
    Type Description
    IObserver<T>

    The observer object implemented using the given actions.

    Type Parameters
    Name Description
    T

    The type of the elements received by the observer.

    Exceptions
    Type Condition
    ArgumentNullException

    onNext is null.

    | Improve this Doc View Source

    Create<T>(Action<T>, Action)

    Creates an observer from the specified OnNext and OnCompleted actions.

    Declaration
    public static IObserver<T> Create<T>(Action<T> onNext, Action onCompleted)
    Parameters
    Type Name Description
    Action<T> onNext

    Observer's OnNext action implementation.

    Action onCompleted

    Observer's OnCompleted action implementation.

    Returns
    Type Description
    IObserver<T>

    The observer object implemented using the given actions.

    Type Parameters
    Name Description
    T

    The type of the elements received by the observer.

    Exceptions
    Type Condition
    ArgumentNullException

    onNext or onCompleted is null.

    | Improve this Doc View Source

    Create<T>(Action<T>, Action<Exception>)

    Creates an observer from the specified OnNext and OnError actions.

    Declaration
    public static IObserver<T> Create<T>(Action<T> onNext, Action<Exception> onError)
    Parameters
    Type Name Description
    Action<T> onNext

    Observer's OnNext action implementation.

    Action<Exception> onError

    Observer's OnError action implementation.

    Returns
    Type Description
    IObserver<T>

    The observer object implemented using the given actions.

    Type Parameters
    Name Description
    T

    The type of the elements received by the observer.

    Exceptions
    Type Condition
    ArgumentNullException

    onNext or onError is null.

    | Improve this Doc View Source

    Create<T>(Action<T>, Action<Exception>, Action)

    Creates an observer from the specified OnNext, OnError, and OnCompleted actions.

    Declaration
    public static IObserver<T> Create<T>(Action<T> onNext, Action<Exception> onError, Action onCompleted)
    Parameters
    Type Name Description
    Action<T> onNext

    Observer's OnNext action implementation.

    Action<Exception> onError

    Observer's OnError action implementation.

    Action onCompleted

    Observer's OnCompleted action implementation.

    Returns
    Type Description
    IObserver<T>

    The observer object implemented using the given actions.

    Type Parameters
    Name Description
    T

    The type of the elements received by the observer.

    Exceptions
    Type Condition
    ArgumentNullException

    onNext or onError or onCompleted is null.

    | Improve this Doc View Source

    NotifyOn<T>(IObserver<T>, IScheduler)

    Schedules the invocation of observer methods on the given scheduler.

    Declaration
    public static IObserver<T> NotifyOn<T>(this IObserver<T> observer, IScheduler scheduler)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer to schedule messages for.

    IScheduler scheduler

    Scheduler to schedule observer messages on.

    Returns
    Type Description
    IObserver<T>

    Observer whose messages are scheduled on the given scheduler.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Exceptions
    Type Condition
    ArgumentNullException

    observer or scheduler is null.

    | Improve this Doc View Source

    NotifyOn<T>(IObserver<T>, SynchronizationContext)

    Schedules the invocation of observer methods on the given synchonization context.

    Declaration
    public static IObserver<T> NotifyOn<T>(this IObserver<T> observer, SynchronizationContext context)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer to schedule messages for.

    SynchronizationContext context

    Synchonization context to schedule observer messages on.

    Returns
    Type Description
    IObserver<T>

    Observer whose messages are scheduled on the given synchonization context.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Exceptions
    Type Condition
    ArgumentNullException

    observer or context is null.

    | Improve this Doc View Source

    Synchronize<T>(IObserver<T>)

    Synchronizes access to the observer such that its callback methods cannot be called concurrently from multiple threads. This overload is useful when coordinating access to an observer. Notice reentrant observer callbacks on the same thread are still possible.

    Declaration
    public static IObserver<T> Synchronize<T>(IObserver<T> observer)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer whose callbacks should be synchronized.

    Returns
    Type Description
    IObserver<T>

    An observer that delivers callbacks to the specified observer in a synchronized manner.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Remarks

    Because a Monitor is used to perform the synchronization, there's no protection against reentrancy from the same thread. Hence, overlapped observer callbacks are still possible, which is invalid behavior according to the observer grammar. In order to protect against this behavior as well, use the Synchronize<T>(IObserver<T>, Boolean) overload, passing true for the second parameter.

    Exceptions
    Type Condition
    ArgumentNullException

    observer is null.

    | Improve this Doc View Source

    Synchronize<T>(IObserver<T>, Boolean)

    Synchronizes access to the observer such that its callback methods cannot be called concurrently. This overload is useful when coordinating access to an observer. The preventReentrancy parameter configures the type of lock used for synchronization.

    Declaration
    public static IObserver<T> Synchronize<T>(IObserver<T> observer, bool preventReentrancy)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer whose callbacks should be synchronized.

    Boolean preventReentrancy

    If set to true, reentrant observer callbacks will be queued up and get delivered to the observer in a sequential manner.

    Returns
    Type Description
    IObserver<T>

    An observer that delivers callbacks to the specified observer in a synchronized manner.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Remarks

    When the preventReentrancy parameter is set to false, behavior is identical to the Synchronize<T>(IObserver<T>) overload which uses a Monitor for synchronization. When the preventReentrancy parameter is set to true, an AsyncLock is used to queue up callbacks to the specified observer if a reentrant call is made.

    Exceptions
    Type Condition
    ArgumentNullException

    observer is null.

    | Improve this Doc View Source

    Synchronize<T>(IObserver<T>, Object)

    Synchronizes access to the observer such that its callback methods cannot be called concurrently by multiple threads, using the specified gate object for use by a Monitor-based lock. This overload is useful when coordinating multiple observers that access shared state by synchronizing on a common gate object. Notice reentrant observer callbacks on the same thread are still possible.

    Declaration
    public static IObserver<T> Synchronize<T>(IObserver<T> observer, object gate)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer whose callbacks should be synchronized.

    Object gate

    Gate object to synchronize each observer call on.

    Returns
    Type Description
    IObserver<T>

    An observer that delivers callbacks to the specified observer in a synchronized manner.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Remarks

    Because a Monitor is used to perform the synchronization, there's no protection against reentrancy from the same thread. Hence, overlapped observer callbacks are still possible, which is invalid behavior according to the observer grammar. In order to protect against this behavior as well, use the Synchronize<T>(IObserver<T>, AsyncLock) overload.

    Exceptions
    Type Condition
    ArgumentNullException

    observer or gate is null.

    | Improve this Doc View Source

    Synchronize<T>(IObserver<T>, AsyncLock)

    Synchronizes access to the observer such that its callback methods cannot be called concurrently, using the specified asynchronous lock to protect against concurrent and reentrant access. This overload is useful when coordinating multiple observers that access shared state by synchronizing on a common asynchronous lock.

    Declaration
    public static IObserver<T> Synchronize<T>(IObserver<T> observer, AsyncLock asyncLock)
    Parameters
    Type Name Description
    IObserver<T> observer

    The observer whose callbacks should be synchronized.

    AsyncLock asyncLock

    Gate object to synchronize each observer call on.

    Returns
    Type Description
    IObserver<T>

    An observer that delivers callbacks to the specified observer in a synchronized manner.

    Type Parameters
    Name Description
    T

    The type of the elements received by the source observer.

    Exceptions
    Type Condition
    ArgumentNullException

    observer or asyncLock is null.

    | Improve this Doc View Source

    ToNotifier<T>(IObserver<T>)

    Creates a notification callback from an observer.

    Declaration
    public static Action<Notification<T>> ToNotifier<T>(this IObserver<T> observer)
    Parameters
    Type Name Description
    IObserver<T> observer

    Observer object.

    Returns
    Type Description
    Action<Notification<T>>

    The action that forwards its input notification to the underlying observer.

    Type Parameters
    Name Description
    T

    The type of the elements received by the observer.

    Exceptions
    Type Condition
    ArgumentNullException

    observer is null.

    | Improve this Doc View Source

    ToObserver<T>(Action<Notification<T>>)

    Creates an observer from a notification callback.

    Declaration
    public static IObserver<T> ToObserver<T>(this Action<Notification<T>> handler)
    Parameters
    Type Name Description
    Action<Notification<T>> handler

    Action that handles a notification.

    Returns
    Type Description
    IObserver<T>

    The observer object that invokes the specified handler using a notification corresponding to each message it receives.

    Type Parameters
    Name Description
    T

    The type of the elements received by the observer.

    Exceptions
    Type Condition
    ArgumentNullException

    handler is null.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX