コード例 #1
0
        public static IDisposable SubscribeAndReplyToExclusive <TMessageRequest, TMessageResponse>(this INetworkBus bus, Func <TMessageRequest, Task <bool> > canReply, Func <TMessageRequest, Task <TMessageResponse> > func, Guid requestReferenceId)
            where TMessageRequest : notnull, IMessage, new()
            where TMessageResponse : notnull, IMessage, new()
        {
            var disposable1 = bus.Subscribe <ExclusiveRequestMessage <TMessageRequest> >(async message =>
            {
                if (await canReply(message.Request))
                {
                    bus.Publish(new ExclusiveResponseMessage <TMessageRequest>(requestReferenceId), null);
                }
            }, null);

            var disposable2 = bus.SubscribeAndReply <ExclusiveAcceptedRequestMessage <TMessageRequest> >(async message =>
            {
                return(new ExclusiveAcceptedResponseMessage <TMessageResponse>(await func(message.Request)));
            }, requestReferenceId);

            return(new CompositeDisposable(disposable1, disposable2));
        }
コード例 #2
0
 public static IDisposable RegisterHandler <TMessageRequest, TMessageResponse>(this INetworkBus bus, IMessageHandler <TMessageRequest, TMessageResponse> handler, Guid?referenceId = null)
     where TMessageRequest : notnull, IMessage, new()
     where TMessageResponse : notnull, IMessage, new()
 {
     return(bus.SubscribeAndReply <TMessageRequest, TMessageResponse>(handler.HandleAsync, referenceId));
 }
コード例 #3
0
 public static IDisposable SubscribeAndReply <TMessageRequest, TMessageResponse>(this INetworkBus bus, Func <TMessageRequest, Task <TMessageResponse> > func, Guid?referenceId)
     where TMessageRequest : notnull, IMessage, new()
     where TMessageResponse : notnull, IMessage, new()
 {
     return(bus.SubscribeAndReply <TMessageRequest>(message => func(message).WaitAndUnwrapException(), referenceId));
 }