Ejemplo n.º 1
0
        /// <summary>
        /// Subscribes an action to be executed for every action posted to the channel. Action should be thread safe.
        /// Action may be invoked on multiple threads.
        /// </summary>
        /// <param name="subscriber"></param>
        /// <param name="subscriptions"></param>
        /// <returns></returns>
        private IDisposable SubscribeOnProducerThreads(Action <T> subscriber, ISubscriptionRegistry subscriptions)
        {
            _subscribers += subscriber;

            var unsubscriber = new Unsubscriber <T>(subscriber, this, subscriptions);

            subscriptions.RegisterSubscription(unsubscriber);

            return(unsubscriber);
        }
Ejemplo n.º 2
0
        private IDisposable Subscribe(Action action, ISubscriptionRegistry subscriptionRegistery)
        {
            Monitor.Enter(syncRoot);
            try
            {
                this.Add(action);
            }
            finally
            {
                Monitor.Exit(syncRoot);
            }

            var subscriptionDisposable = new EventSubscriptionDisposable(action, this, subscriptionRegistery);

            subscriptionRegistery.RegisterSubscription(subscriptionDisposable);
            return(subscriptionDisposable);
        }