public async Task BecomeConsumer(Guid streamId, string streamNamespace, string providerToUse) { logger.Info("BecomeConsumer"); IStreamProvider streamProvider = GetStreamProvider(providerToUse); consumer = streamProvider.GetStream<int>(streamId, streamNamespace); consumerHandle = await consumer.SubscribeAsync(OnNextAsync, OnErrorAsync, OnActivateAsync); }
public static IAsyncObservable <TSource> SingleOrDefaultAsync <TSource>(this IAsyncObservable <TSource> source) => SingleOrDefault(source);
public static IAsyncObservable <(T1, T2)> Zip <T1, T2>(this IAsyncObservable <T1> source1, IAsyncObservable <T2> source2) { if (source1 == null)
public static IAsyncObservable <TSource> While <TSource>(Func <Task <bool> > condition, IAsyncObservable <TSource> source) { if (condition == null) { throw new ArgumentNullException(nameof(condition)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } return(Create <TSource>(async observer => { var subscription = new SerialAsyncDisposable(); var o = default(IAsyncObserver <TSource>); o = AsyncObserver.CreateUnsafe <TSource>( observer.OnNextAsync, observer.OnErrorAsync, MoveNext ); async Task MoveNext() { var b = default(bool); try { b = await condition().ConfigureAwait(false); } catch (Exception ex) { await observer.OnErrorAsync(ex).ConfigureAwait(false); return; } if (b) { var sad = new SingleAssignmentAsyncDisposable(); await subscription.AssignAsync(sad).ConfigureAwait(false); var d = await source.SubscribeSafeAsync(o).ConfigureAwait(false); await sad.AssignAsync(d).ConfigureAwait(false); } else { await observer.OnCompletedAsync().ConfigureAwait(false); } } await MoveNext().ConfigureAwait(false); return subscription; })); }
public static ValueTask <IAsyncDisposable> Repeat <TSource>(IAsyncObserver <TSource> observer, IAsyncObservable <TSource> source, int repeatCount) { if (observer == null) { throw new ArgumentNullException(nameof(observer)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } if (repeatCount < 0) { throw new ArgumentNullException(nameof(repeatCount)); } async ValueTask <IAsyncDisposable> CoreAsync() { var(sink, inner) = Concat(observer, Enumerable.Repeat(source, repeatCount).GetEnumerator()); var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false); return(StableCompositeAsyncDisposable.Create(subscription, inner)); } return(CoreAsync()); }
public static IAsyncObservable <TSource> LastAsync <TSource>(this IAsyncObservable <TSource> source, Func <TSource, ValueTask <bool> > predicate) => Last(source, predicate);
/// <summary> /// Subscribe a consumer to this observable using delegates. /// This method is a helper for the IAsyncObservable.SubscribeAsync allowing the subscribing class to inline the /// handler methods instead of requiring an instance of IAsyncObserver. /// </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 IAsyncObserver.OnNextAsync.</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 IAsyncObservable <T> obs, Func <T, StreamSequenceToken, Task> onNextAsync) { return(obs.SubscribeAsync(onNextAsync, DefaultOnError, DefaultOnCompleted)); }
public static IAsyncObservable <TResult> Join <TLeft, TRight, TLeftDuration, TRightDuration, TResult>(this IAsyncObservable <TLeft> left, IAsyncObservable <TRight> right, Func <TLeft, IAsyncObservable <TLeftDuration> > leftDurationSelector, Func <TRight, IAsyncObservable <TRightDuration> > rightDurationSelector, Func <TLeft, TRight, TResult> resultSelector) { if (left == null) { throw new ArgumentNullException(nameof(left)); } if (right == null) { throw new ArgumentNullException(nameof(right)); } if (leftDurationSelector == null) { throw new ArgumentNullException(nameof(leftDurationSelector)); } if (rightDurationSelector == null) { throw new ArgumentNullException(nameof(rightDurationSelector)); } if (resultSelector == null) { throw new ArgumentNullException(nameof(resultSelector)); } return(Create <TResult>(async observer => { var subscriptions = new CompositeAsyncDisposable(); var(leftObserver, rightObserver, disposable) = AsyncObserver.Join(observer, subscriptions, leftDurationSelector, rightDurationSelector, resultSelector); var leftSubscription = await left.SubscribeSafeAsync(leftObserver).ConfigureAwait(false); await subscriptions.AddAsync(leftSubscription).ConfigureAwait(false); var rightSubscription = await right.SubscribeSafeAsync(rightObserver).ConfigureAwait(false); await subscriptions.AddAsync(rightSubscription).ConfigureAwait(false); return disposable; })); }
public static IAsyncObservable <IGroupedAsyncObservable <TKey, TElement> > GroupBy <TSource, TKey, TElement>(this IAsyncObservable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (keySelector == null) { throw new ArgumentNullException(nameof(keySelector)); } if (elementSelector == null) { throw new ArgumentNullException(nameof(elementSelector)); } return(Create <IGroupedAsyncObservable <TKey, TElement> >(observer => GroupByCore(source, observer, (o, d) => AsyncObserver.GroupBy(o, d, keySelector, elementSelector)))); }
public static IAsyncObservable <IGroupedAsyncObservable <TKey, TSource> > GroupBy <TSource, TKey>(this IAsyncObservable <TSource> source, Func <TSource, TKey> keySelector, int capacity, IEqualityComparer <TKey> comparer) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (keySelector == null) { throw new ArgumentNullException(nameof(keySelector)); } if (capacity < 0) { throw new ArgumentOutOfRangeException(nameof(capacity)); } if (comparer == null) { throw new ArgumentNullException(nameof(comparer)); } return(Create <IGroupedAsyncObservable <TKey, TSource> >(observer => GroupByCore(source, observer, (o, d) => AsyncObserver.GroupBy(o, d, keySelector, capacity, comparer)))); }
private static async ValueTask <IAsyncDisposable> GroupByCore <TSource, TKey, TElement>(IAsyncObservable <TSource> source, IAsyncObserver <IGroupedAsyncObservable <TKey, TElement> > observer, Func <IAsyncObserver <IGroupedAsyncObservable <TKey, TElement> >, IAsyncDisposable, (IAsyncObserver <TSource>, IAsyncDisposable)> createObserver)
public static IAsyncObservable <TSource> LastOrDefaultAsync <TSource>(this IAsyncObservable <TSource> source, Func <TSource, Task <bool> > predicate) => LastOrDefault(source, predicate);
public static IAsyncObservable <TSource> SkipUntil <TSource, TUntil>(this IAsyncObservable <TSource> source, IAsyncObservable <TUntil> until) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (until == null) { throw new ArgumentNullException(nameof(until)); } return(Create <TSource>(async observer => { var(sourceObserver, untilObserver) = AsyncObserver.SkipUntil <TSource, TUntil>(observer); var sourceTask = source.SubscribeSafeAsync(sourceObserver); var untilTask = until.SubscribeSafeAsync(untilObserver); // REVIEW: Consider concurrent subscriptions. var d1 = await sourceTask.ConfigureAwait(false); var d2 = await untilTask.ConfigureAwait(false); return StableCompositeAsyncDisposable.Create(d1, d2); })); }
public static IAsyncObservable <TSource> FirstAsync <TSource>(this IAsyncObservable <TSource> source, Func <TSource, bool> predicate) => First(source, predicate);
public static IAsyncObservable <IGroupedAsyncObservable <TKey, TSource> > GroupByUntil <TSource, TKey, TDuration>(this IAsyncObservable <TSource> source, Func <TSource, TKey> keySelector, Func <IGroupedAsyncObservable <TKey, TSource>, IAsyncObservable <TDuration> > durationSelector, int capacity) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (keySelector == null) { throw new ArgumentNullException(nameof(keySelector)); } if (durationSelector == null) { throw new ArgumentNullException(nameof(durationSelector)); } if (capacity < 0) { throw new ArgumentOutOfRangeException(nameof(capacity)); } return(Create <IGroupedAsyncObservable <TKey, TSource> >(observer => GroupByUntilCore <TSource, TKey, TSource, TDuration>(source, observer, (o, d) => AsyncObserver.GroupByUntil(o, d, keySelector, durationSelector, capacity)))); }
public EventSource(IAsyncObservable <T> source, Action <Action <T>, /*object,*/ T> invokeHandler) { _source = source; _invokeHandler = invokeHandler; _subscriptions = new Dictionary <Delegate, Stack <IDisposable> >(); }
public static IAsyncObservable <TSource> Timeout <TSource>(this IAsyncObservable <TSource> source, TimeSpan dueTime, IAsyncObservable <TSource> other, IAsyncScheduler scheduler) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (other == null) { throw new ArgumentNullException(nameof(other)); } if (scheduler == null) { throw new ArgumentNullException(nameof(scheduler)); } return(Create <TSource>(async observer => { var sourceSubscription = new SingleAssignmentAsyncDisposable(); var(sink, disposable) = await AsyncObserver.Timeout(observer, sourceSubscription, dueTime, other, scheduler).ConfigureAwait(false); var sourceSubscriptionInner = await source.SubscribeSafeAsync(sink).ConfigureAwait(false); await sourceSubscription.AssignAsync(sourceSubscriptionInner).ConfigureAwait(false); return disposable; })); }
public EventPatternSource(IAsyncObservable <EventPattern <object, TEventArgs> > source, Action <Action <object, TEventArgs>, /*object,*/ EventPattern <object, TEventArgs> > invokeHandler) : base(source, invokeHandler) { }
public static IAsyncObservable <(TFirst first, TSecond second)> WithLatestFrom <TFirst, TSecond>(this IAsyncObservable <TFirst> first, IAsyncObservable <TSecond> second) { if (first == null)
public static IAsyncObservable <TSource> LastAsync <TSource>(this IAsyncObservable <TSource> source) => Last(source);
internal AsyncPattern(IAsyncObservable <TSource1> source1) { Source1 = source1; }
public AsyncJoinObserver(IAsyncObservable <T> source, Func <Exception, Task> onError) { _source = source; _onError = onError; }
public static IAsyncObservable <TSource> TakeLast <TSource>(this IAsyncObservable <TSource> source, TimeSpan duration, IAsyncScheduler scheduler) => TakeLast(source, duration, scheduler, scheduler);
public static IDisposable Subscribe <T>(this IAsyncObservable <T> source, Func <T, Task> onHappen) { return(source.Subscribe(new AsyncObserver <T>(onHappen))); }
public static IAsyncObservable <TSource> Concat <TSource>(this IAsyncObservable <TSource> first, IAsyncObservable <TSource> second) { if (first == null) { throw new ArgumentNullException(nameof(first)); } if (second == null) { throw new ArgumentNullException(nameof(second)); } return(Create( first, second, static async(first, second, observer) => { var(sink, inner) = AsyncObserver.Concat(observer, second); var subscription = await first.SubscribeSafeAsync(sink).ConfigureAwait(false); return StableCompositeAsyncDisposable.Create(subscription, inner); })); }
public static IAsyncObservable <TSource> Sample <TSource, TSample>(this IAsyncObservable <TSource> source, IAsyncObservable <TSample> sampler) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (sampler == null) { throw new ArgumentNullException(nameof(sampler)); } return(Create <TSource>(async observer => { var(sourceSink, samplerSink) = AsyncObserver.Sample <TSource, TSample>(observer); var sourceSubscription = await source.SubscribeSafeAsync(sourceSink).ConfigureAwait(false); var samplerSubscription = await sampler.SubscribeSafeAsync(samplerSink).ConfigureAwait(false); return StableCompositeAsyncDisposable.Create(sourceSubscription, samplerSubscription); })); }
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); })); }
public static IAsyncObservable <TSource> SingleOrDefaultAsync <TSource>(this IAsyncObservable <TSource> source, Func <TSource, ValueTask <bool> > predicate) => SingleOrDefault(source, predicate);
// 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); })); }
public Take(IAsyncObservable <T> source, int count) { _source = source; _count = count; }
public static IAsyncObservable <IGroupedAsyncObservable <TKey, TElement> > GroupByUntil <TSource, TKey, TElement, TDuration>(this IAsyncObservable <TSource> source, Func <TSource, Task <TKey> > keySelector, Func <TSource, Task <TElement> > elementSelector, Func <IGroupedAsyncObservable <TKey, TElement>, IAsyncObservable <TDuration> > durationSelector, IEqualityComparer <TKey> comparer) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (keySelector == null) { throw new ArgumentNullException(nameof(keySelector)); } if (elementSelector == null) { throw new ArgumentNullException(nameof(elementSelector)); } if (durationSelector == null) { throw new ArgumentNullException(nameof(durationSelector)); } if (comparer == null) { throw new ArgumentNullException(nameof(comparer)); } return(Create <IGroupedAsyncObservable <TKey, TElement> >(observer => GroupByUntilCore <TSource, TKey, TElement, TDuration>(source, observer, (o, d) => AsyncObserver.GroupByUntil(o, d, keySelector, elementSelector, durationSelector, comparer)))); }