/// <summary>
        /// Helper method to allow awaiting a disposable. This way we can ensure if calling from outside a disposable we await everything currently using the actual group.
        /// </summary>
        /// <param name="group"></param>
        /// <param name="fromDisposable"></param>
        /// <returns></returns>
        private bool RemoveCommandGroup(ICommandGroup group, bool fromDisposable)
        {
            //TODO: Is this necessary?
            if (!fromDisposable)
            {
                RefCountDisposable holdIt;
                lock (_gate)
                    holdIt = CommandGroups.GetValueOrDefault(group);

                if (holdIt == default)
                {
                    return(false);
                }
                if (!holdIt.IsDisposed)
                {
                    holdIt.Dispose();
                }
                return(true);
            }
            lock (_gate)
            {
                if (!CommandGroups.ContainsKey(group))
                {
                    return(false);
                }
                for (; ;)
                {
                    if (ImmutableInterlocked.Update(ref CommandGroups, (x, y) => x.Remove(y), group))
                    {
                        break;
                    }
                }
                return(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Increment the version for the node passed as argument. Returns a new VectorClock.
        /// </summary>
        /// <param name="node">Increment the vector clock value for a particular node.</param>
        /// <returns>An updated <see cref="VectorClock"/> instance.</returns>
        public VectorClock Increment(Node node)
        {
            var currentTimestamp = _versions.GetValueOrDefault(node, Timestamp.Zero);

            return(new VectorClock(_versions.SetItem(node, currentTimestamp + 1)));
        }