コード例 #1
0
        /// <summary>
        /// Subscribe a consumer to this observable using delegates.
        /// This method is a helper for the IAsyncBatchObservable.SubscribeAsync allowing the subscribing class to inline the
        /// handler methods instead of requiring an instance of IAsyncBatchObserver.
        /// </summary>
        /// <typeparam name="T">The type of object produced by the observable.</typeparam>
        /// <param name="obs">The Observable object.</param>
        /// <param name="onNextAsync">Delegate that is called for IAsyncBatchObserver.OnNextAsync.</param>
        /// <param name="onErrorAsync">Delegate that is called for IAsyncBatchObserver.OnErrorAsync.</param>
        /// <param name="onCompletedAsync">Delegate that is called for IAsyncBatchObserver.OnCompletedAsync.</param>
        /// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
        /// The consumer may unsubscribe by using this handle.
        /// The subscription remains active for as long as it is not explicitly unsubscribed.</returns>
        public static Task <StreamSubscriptionHandle <T> > SubscribeAsync <T>(this IAsyncBatchObservable <T> obs,
                                                                              Func <IList <SequentialItem <T> >, Task> onNextAsync,
                                                                              Func <Exception, Task> onErrorAsync,
                                                                              Func <Task> onCompletedAsync)
        {
            var genericObserver = new GenericAsyncBatchObserver <T>(onNextAsync, onErrorAsync, onCompletedAsync);

            return(obs.SubscribeAsync(genericObserver));
        }
コード例 #2
0
        /// <summary>
        /// Resumes consumption of a stream using delegates.
        /// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
        /// handler methods instead of requiring an instance of IAsyncBatchObserver.
        /// </summary>
        /// <typeparam name="T">The type of object produced by the observable.</typeparam>
        /// <param name="handle">The subscription handle.</param>
        /// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
        /// <param name="onErrorAsync">Delegate that is called for IAsyncObserver.OnErrorAsync.</param>
        /// <param name="onCompletedAsync">Delegate that is called for IAsyncObserver.OnCompletedAsync.</param>
        /// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
        /// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
        /// The consumer may unsubscribe by using this handle.
        /// The subscription remains active for as long as it is not explicitly unsubscribed.
        /// </returns>
        public static Task <StreamSubscriptionHandle <T> > ResumeAsync <T>(this StreamSubscriptionHandle <T> handle,
                                                                           Func <IList <SequentialItem <T> >, Task> onNextAsync,
                                                                           Func <Exception, Task> onErrorAsync,
                                                                           Func <Task> onCompletedAsync,
                                                                           StreamSequenceToken token = null)
        {
            var genericObserver = new GenericAsyncBatchObserver <T>(onNextAsync, onErrorAsync, onCompletedAsync);

            return(handle.ResumeAsync(genericObserver, token));
        }