From f4725f5d81e8715a55ab3e4ea6791f903e9e9ad4 Mon Sep 17 00:00:00 2001 From: dionjansen Date: Sun, 3 Jan 2021 19:05:29 +0100 Subject: [PATCH] Refactored elapsed calc --- src/DotPulsar/Internal/UnackedMessageTracker.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DotPulsar/Internal/UnackedMessageTracker.cs b/src/DotPulsar/Internal/UnackedMessageTracker.cs index d52da34da..2b5ef030f 100644 --- a/src/DotPulsar/Internal/UnackedMessageTracker.cs +++ b/src/DotPulsar/Internal/UnackedMessageTracker.cs @@ -13,15 +13,16 @@ public readonly struct AwaitingAck { public MessageId MessageId { get; } - public Stopwatch Stopwatch { get; } + public long Timestamp { get; } public AwaitingAck(MessageId messageId) { MessageId = messageId; - Stopwatch = Stopwatch.StartNew(); + Timestamp = Stopwatch.GetTimestamp(); } - public TimeSpan Elapsed => Stopwatch.Elapsed; + public TimeSpan Elapsed => TimeSpan.FromTicks( + (long) ((Stopwatch.GetTimestamp() - Timestamp) / (double)Stopwatch.Frequency * TimeSpan.TicksPerSecond)); } public sealed class UnackedMessageTracker : IUnackedMessageTracker