From 0ef7f07e12426ea68876747f235498961376b184 Mon Sep 17 00:00:00 2001 From: Brah McDude <77924970+brah-mcdude@users.noreply.github.com> Date: Fri, 14 May 2021 16:43:18 +0300 Subject: [PATCH] Merge pull request #5011 from brah-mcdude/dev Update TestScheduler.cs --- src/core/Akka.TestKit/TestScheduler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/Akka.TestKit/TestScheduler.cs b/src/core/Akka.TestKit/TestScheduler.cs index 8a224a8a80f..4315cc815a1 100644 --- a/src/core/Akka.TestKit/TestScheduler.cs +++ b/src/core/Akka.TestKit/TestScheduler.cs @@ -88,10 +88,14 @@ private void InternalSchedule(TimeSpan? initialDelay, TimeSpan delay, ICanTell r { var scheduledTime = _now.Add(initialDelay ?? delay).UtcTicks; - if (!_scheduledWork.TryGetValue(scheduledTime, out var tickItems)) + ConcurrentQueue tickItems; + while (!_scheduledWork.TryGetValue(scheduledTime, out tickItems)) { tickItems = new ConcurrentQueue(); - _scheduledWork.TryAdd(scheduledTime, tickItems); + if (_scheduledWork.TryAdd(scheduledTime, tickItems)) + { + break; + } } var type = message == null ? ScheduledItem.ScheduledItemType.Action : ScheduledItem.ScheduledItemType.Message;