public IDisposable Subscribe <T>(Action <T> handler) where T : class, IMessage { var handlerKey = new HandlerKey(typeof(T), default(PeerId)); _handlers[handlerKey] = x => { handler((T)x); return(null); }; return(new DisposableAction(() => _handlers.Remove(handlerKey))); }
public IDisposable Subscribe(Subscription subscription, Action <IMessage> handler) { lock (_subscriptions) { _subscriptions.Add(subscription); } var handlerKey = new HandlerKey(subscription.MessageTypeId.GetMessageType(), default(PeerId)); _handlers[handlerKey] = x => { handler(x); return(null); }; return(new DisposableAction(() => { _handlers.Remove(handlerKey); lock (_subscriptions) { _subscriptions.Remove(subscription); } })); }