|
|
@@ -133,33 +133,24 @@ public class TimedEvents : ITimedEvents
|
|
|
k -= 100;
|
|
|
}
|
|
|
|
|
|
- _timeouts.Add (NudgeToUniqueKey (k, time == TimeSpan.Zero), timeout);
|
|
|
+ _timeouts.Add (NudgeToUniqueKey (k), timeout);
|
|
|
Added?.Invoke (this, new (timeout, k));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Finds the closest number to <paramref name="k"/> that is not present in <see cref="_timeouts"/>.
|
|
|
- /// For immediate execution timeouts (decrementForImmediate=true), decrements to maintain FIFO order.
|
|
|
- /// For delayed timeouts, increments to maintain order.
|
|
|
+ /// Finds the closest number to <paramref name="k"/> that is not present in <see cref="_timeouts"/>
|
|
|
+ /// (incrementally).
|
|
|
/// </summary>
|
|
|
- /// <param name="k">The initial key to try</param>
|
|
|
- /// <param name="decrementForImmediate">If true, decrements on collision; otherwise increments</param>
|
|
|
- /// <returns>A unique key</returns>
|
|
|
- private long NudgeToUniqueKey (long k, bool decrementForImmediate)
|
|
|
+ /// <param name="k"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private long NudgeToUniqueKey (long k)
|
|
|
{
|
|
|
lock (_timeoutsLockToken)
|
|
|
{
|
|
|
while (_timeouts.ContainsKey (k))
|
|
|
{
|
|
|
- if (decrementForImmediate)
|
|
|
- {
|
|
|
- k--;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- k++;
|
|
|
- }
|
|
|
+ k++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -194,8 +185,7 @@ public class TimedEvents : ITimedEvents
|
|
|
{
|
|
|
lock (_timeoutsLockToken)
|
|
|
{
|
|
|
- // When re-adding non-executed timeouts, increment on collision to maintain original order
|
|
|
- _timeouts.Add (NudgeToUniqueKey (k, decrementForImmediate: false), timeout);
|
|
|
+ _timeouts.Add (NudgeToUniqueKey (k), timeout);
|
|
|
}
|
|
|
}
|
|
|
}
|