// ReSharper disable once UnusedMember.Local private IDisposable AsyncSubscribeToChannel <T>(IAsyncFiber fiber, IHandleAsync <T> receive) { Type type = typeof(T); IChannel <T> channel = (IChannel <T>)_channels.GetOrAdd(type, _ => new Channel <T>()); return(channel.Subscribe(fiber, receive.HandleAsync)); }
public AsyncRequestResponsePipelineHandler( IHandleAsync <TRequest, TResponse> inner, IPreRequestHandler <TRequest>[] preRequestHandlers, IPostRequestResponseHandler <TRequest, TResponse>[] postRequestResponseHandlers) { _inner = inner; _preRequestHandlers = preRequestHandlers; _postRequestResponseHandlers = postRequestResponseHandlers; }
public AsyncEventHandler( IVersionRepository versionRepository, IEventFeed <AsyncEventHandler <TConcreteHandlerType, TSubscribedDomainEvent> > eventFeed, IHandleAsync <TSubscribedDomainEvent> handler) { _versionRepository = versionRepository; _eventFeed = eventFeed; _handler = handler; }
/// <inheritdoc/> public long Subscribe(IHandleAsync <T> subscriber, SynchronizationContext synchronizationContext = null, bool serializeNotification = false) { var id = Increment(ref NewSubscriptionId); Subscriptions[id] = CreateActionBlock(subscriber, synchronizationContext, serializeNotification); return(id); }
private static ActionBlock <T> CreateActionBlock(IHandleAsync <T> subscriber, SynchronizationContext synchronizationContext, bool serializeNotification) { var options = new ExecutionDataflowBlockOptions(); if (serializeNotification) { options.MaxDegreeOfParallelism = 1; } var reference = new WeakReference(subscriber); return(new ActionBlock <T>(message => { async void DoPublish(object _) { try { var target = reference.Target as IHandleAsync <T>; if (target is null) { return; } await target.HandleAsync(message) .ConfigureAwait(false); } catch { } } if (synchronizationContext == null) { DoPublish(null); } else { synchronizationContext.Post(DoPublish, null); } }, options)); }
public void Register <T>(IHandleAsync <T> handler) { AddHandler(typeof(T), handler); }