Esempio n. 1
0
 public async UniTask <IDisposable> SubscribeAsync(IAsyncMessageHandler <TMessage> handler, CancellationToken cancellationToken)
 {
     if (IsValueType || lastMessage != null)
     {
         await handler.HandleAsync(lastMessage, cancellationToken);
     }
     return(core.Subscribe(handler));
 }
Esempio n. 2
0
        public async ValueTask <IAsyncDisposable> SubscribeAsync(TKey key, IAsyncMessageHandler <TMessage> handler, AsyncMessageHandlerFilter <TMessage>[] filters, CancellationToken cancellationToken)
        {
            handler = asyncMessageHandlerFactory.CreateAsyncMessageHandler(handler, filters); // with filter

            var channel = CreateChannel(key);

            var mq = await connectionFactory.GetConnectionMultiplexer(key).GetSubscriber().SubscribeAsync(channel).ConfigureAwait(false);

            mq.OnMessage(async message =>
            {
                var v = serializer.Deserialize <TMessage>((byte[])message.Message);
                await handler.HandleAsync(v, CancellationToken.None).ConfigureAwait(false);
            });

            return(new Subscription(mq));
        }