Esempio n. 1
0
        void SubscribeInternal(SignalSubscriptionId id, Action <object> callback)
        {
            Assert.That(!_subscriptionMap.ContainsKey(id),
                        "Tried subscribing to the same signal with the same callback on UniDi.SignalBus");

            var declaration = GetDeclaration(id.SignalId);

            if (declaration == null)
            {
                throw Assert.CreateException("Tried subscribing to undeclared signal '{0}'!", id.SignalId);
            }

            var subscription = _subscriptionPool.Spawn(callback, declaration);

            _subscriptionMap.Add(id, subscription);
        }
Esempio n. 2
0
        void UnsubscribeInternal(SignalSubscriptionId id, bool throwIfMissing)
        {
            SignalSubscription subscription;

            if (_subscriptionMap.TryGetValue(id, out subscription))
            {
                _subscriptionMap.RemoveWithConfirm(id);
                subscription.Dispose();
            }
            else
            {
                if (throwIfMissing)
                {
                    throw Assert.CreateException(
                              "Called unsubscribe for signal '{0}' but could not find corresponding subscribe.  If this is intentional, call TryUnsubscribe instead.", id.SignalId);
                }
            }
        }