示例#1
0
        public static async ValueTask <TMessage> FirstAsync <TMessage>(this IBufferedAsyncSubscriber <TMessage> subscriber, CancellationToken cancellationToken, Func <TMessage, bool> predicate, params AsyncMessageHandlerFilter <TMessage>[] filters)
        {
            var predicateFilter = new AsyncPredicateFilter <TMessage>(predicate);

            filters = (filters.Length == 0)
                ? new[] { predicateFilter }
                : ArrayUtil.ImmutableAdd(filters, predicateFilter);

            return(await new ValueTask <TMessage>(await FirstAsyncAsyncBufferedMessageHandler <TMessage> .CreateAsync(subscriber, cancellationToken, filters), 0));
        }
示例#2
0
        public static ValueTask <IAsyncDisposable> SubscribeAsync <TKey, TMessage>(this IDistributedSubscriber <TKey, TMessage> subscriber, TKey key, Func <TMessage, CancellationToken, ValueTask> handler, Func <TMessage, bool> predicate, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken = default)
        {
            var predicateFilter = new AsyncPredicateFilter <TMessage>(predicate);

            filters = (filters.Length == 0)
                ? new[] { predicateFilter }
                : Append(filters, predicateFilter);

            return(subscriber.SubscribeAsync(key, new AnonymousAsyncMessageHandler <TMessage>(handler), filters, cancellationToken));
        }
示例#3
0
        public static IDisposable Subscribe <TMessage>(this IAsyncSubscriber <TMessage> subscriber, Func <TMessage, CancellationToken, ValueTask> handler, Func <TMessage, bool> predicate, params AsyncMessageHandlerFilter <TMessage>[] filters)
        {
            var predicateFilter = new AsyncPredicateFilter <TMessage>(predicate);

            filters = (filters.Length == 0)
                ? new[] { predicateFilter }
                : ArrayUtil.ImmutableAdd(filters, predicateFilter);

            return(subscriber.Subscribe(new AnonymousAsyncMessageHandler <TMessage>(handler), filters));
        }
示例#4
0
        public static ValueTask <IDisposable> SubscribeAsync <TMessage>(this IBufferedAsyncSubscriber <TMessage> subscriber, Func <TMessage, CancellationToken, ValueTask> handler, Func <TMessage, bool> predicate, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken = default)
        {
            var predicateFilter = new AsyncPredicateFilter <TMessage>(predicate);

            filters = (filters.Length == 0)
                ? new[] { predicateFilter }
                : ArrayUtil.ImmutableAdd(filters, predicateFilter);

            return(subscriber.SubscribeAsync(new AnonymousAsyncMessageHandler <TMessage>(handler), filters, cancellationToken));
        }
示例#5
0
        public static UniTask <TMessage> FirstAsync <TMessage>(this IAsyncSubscriber <TMessage> subscriber, CancellationToken cancellationToken, Func <TMessage, bool> predicate, params AsyncMessageHandlerFilter <TMessage>[] filters)
        {
            var predicateFilter = new AsyncPredicateFilter <TMessage>(predicate);

            filters = (filters.Length == 0)
                ? new[] { predicateFilter }
                : ArrayUtil.ImmutableAdd(filters, predicateFilter);

            return(new UniTask <TMessage>(new FirstAsyncAsyncMessageHandler <TMessage>(subscriber, cancellationToken, filters), 0));
        }