Ejemplo n.º 1
0
    /// <summary>
    ///     Subscribes the given callback on the event. The callback will be invoked every time the event
    ///     is raised. This method establishes a strong reference between the event source and the object
    ///     holding the supplied callback, aka subscriber. That means as long as the event source is kept
    ///     in memory, it will also keep the subscriber in memory. To break this strong reference, you can
    ///     dispose the returned subscription.
    /// </summary>
    ///
    /// <param name="action">
    ///     The callback to subscribe on the event.
    /// </param>
    ///
    /// <returns>
    ///     An object that represents the newly created subscription. Disposing this object will cancel the
    ///     subscription and remove the callback from the event source's subscription list.
    /// </returns>
    ///
    /// <exception cref="ArgumentNullException">
    ///     A null reference was passed to a method that did not accept it as a valid argument.
    /// </exception>
    public readonly IDisposable Subscribe(Action <T> action)
    {
        if (action == null)
        {
            throw new ArgumentNullException(nameof(action));
        }

        if (mSource == null)
        {
            return(NullSubscription.Instance);
        }

        return(mSource.Add(action));
    }
Ejemplo n.º 2
0
 private IObservable <ISubbleEvent> InitEvents()
 {
     return(Observable.Create(
                (IObserver <ISubbleEvent> source) =>
     {
         EventSource.Add(source);
         return Disposable.Empty;
     }));
 }