public static UnsubscribeAction ConnectToRouter <T>(this IPipelineSink <T> pipeline, IPipelineSink <T> sink, Func <bool> unsubscribe) where T : class { UnsubscribeAction result = pipeline.ConnectToRouter(sink); return(() => result() && unsubscribe()); }
public UnsubscribeAction Connect(TKey correlationId, IPipelineSink <TMessage> sink) { IPipelineSink <TMessage> keySink = null; if (_sinks.ReadLock(x => x.TryGetValue(correlationId, out keySink)) == false) { // we need to add the sink if it doesn't exist _sinks.WriteLock(x => { if (x.TryGetValue(correlationId, out keySink) == false) { MessageRouter <TMessage> keyRouter = new CorrelatedMessageSinkRouter <TMessage, TKey>(correlationId); x.Add(correlationId, keyRouter); keySink = keyRouter; } }); } return(keySink.ConnectToRouter(sink, () => _sinks.WriteLock(x => DisconnectIfEmpty(x, correlationId)))); }