From 795384e9b6f51d135aff58aa76345293b5a1fce5 Mon Sep 17 00:00:00 2001 From: Brah McDude <77924970+brah-mcdude@users.noreply.github.com> Date: Thu, 13 May 2021 05:31:40 +0300 Subject: [PATCH] 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;