예제 #1
0
        // Protected & private methods

        protected override async Task RunInternalAsync(CancellationToken cancellationToken)
        {
            var dueAt = _start + Quanta;

            for (;; dueAt += Quanta)
            {
                // ReSharper disable once InconsistentlySynchronizedField
                if (dueAt > Clock.Now)
                {
                    await Clock.DelayAsync(dueAt, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }
                IReadOnlyDictionary <TTimer, long> minSet;
                lock (_lock) {
                    minSet = _timers.ExtractMinSet(minPriority);
                    ++minPriority;
                }
                if (_fireHandler != null && minSet.Count != 0)
                {
                    foreach (var(timer, _) in minSet)
                    {
                        try {
                            _fireHandler !.Invoke(timer);
                        }
                        catch {
                            // Intended suppression
                        }
                    }
                }
            }
        }
        public void UpdateMinPriorityTest()
        {
            var heap = new RadixHeapSet <int>();

            for (var i = 1; i < 100; i += 5)
            {
                heap.AddOrUpdate(i, i);
                heap.Count.Should().Be((i + 4) / 5);
                heap.PeekMin().Value.Value.Should().Be(1);
            }
            for (var i = 0; i < 95; i++)
            {
                var minSet = heap.ExtractMinSet(i);
                var isFit  = 0 == (i - 1) % 5;
                minSet.Count.Should().Be(isFit ? 1 : 0);
                if (isFit)
                {
                    minSet.Single().Value.Should().Be(i);
                }
            }
        }