Ejemplo n.º 1
0
        public static IAsyncObservable <IList <TSource> > Buffer <TSource>(this IAsyncObservable <TSource> source, TimeSpan timeSpan, int count, IAsyncScheduler scheduler)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (timeSpan < TimeSpan.Zero)
            {
                throw new ArgumentNullException(nameof(timeSpan));
            }
            if (count <= 0)
            {
                throw new ArgumentNullException(nameof(count));
            }
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            return(Create <IList <TSource> >(async observer =>
            {
                var(sink, timer) = await AsyncObserver.Buffer(observer, timeSpan, count, scheduler).ConfigureAwait(false);

                var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);

                return StableCompositeAsyncDisposable.Create(subscription, timer);
            }));
        }
Ejemplo n.º 2
0
        public static IAsyncObservable <IList <TSource> > Buffer <TSource>(this IAsyncObservable <TSource> source, int count)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (count <= 0)
            {
                throw new ArgumentNullException(nameof(count));
            }

            return(Create <IList <TSource> >(observer => source.SubscribeSafeAsync(AsyncObserver.Buffer(observer, count))));
        }
Ejemplo n.º 3
0
        // REVIEW: This overload is inherited from Rx but arguably a bit esoteric as it doesn't provide context to the closing selector.

        public static IAsyncObservable <IList <TSource> > Buffer <TSource, TBufferClosing>(this IAsyncObservable <TSource> source, Func <IAsyncObservable <TBufferClosing> > bufferClosingSelector)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (bufferClosingSelector == null)
            {
                throw new ArgumentNullException(nameof(bufferClosingSelector));
            }

            return(Create <IList <TSource> >(async observer =>
            {
                var(sourceObserver, closingDisposable) = await AsyncObserver.Buffer <TSource, TBufferClosing>(observer, bufferClosingSelector).ConfigureAwait(false);

                var sourceSubscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);

                return StableCompositeAsyncDisposable.Create(sourceSubscription, closingDisposable);
            }));
        }
Ejemplo n.º 4
0
        public static IAsyncObservable <IList <TSource> > Buffer <TSource, TBufferBoundary>(this IAsyncObservable <TSource> source, IAsyncObservable <TBufferBoundary> bufferBoundaries)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (bufferBoundaries == null)
            {
                throw new ArgumentNullException(nameof(bufferBoundaries));
            }

            return(Create <IList <TSource> >(async observer =>
            {
                var(sourceObserver, boundariesObserver) = AsyncObserver.Buffer <TSource, TBufferBoundary>(observer);

                var sourceSubscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);
                var boundariesSubscription = await bufferBoundaries.SubscribeSafeAsync(boundariesObserver).ConfigureAwait(false);

                return StableCompositeAsyncDisposable.Create(sourceSubscription, boundariesSubscription);
            }));
        }