diff --git a/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs b/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs index 2c9c905d8..10d8c8f86 100644 --- a/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs +++ b/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs @@ -106,13 +106,13 @@ public async ValueTask TryAcquireAsync(CancellationToken token = defaul { ObjectDisposedException.ThrowIf(IsDisposingOrDisposed, this); - var ts = new Timestamp(); + var ts = new Timestamp(provider); if (await TryAcquireCoreAsync(token).ConfigureAwait(false) is { } response) { identity = response.Identity; await CancelAndStopTimerAsync().ConfigureAwait(false); - var remainingTime = AdjustTimeToLive(response.TimeToLive) - ts.Elapsed; + var remainingTime = AdjustTimeToLive(response.TimeToLive) - ts.GetElapsedTime(provider); if (remainingTime > TimeSpan.Zero) { timer = provider.CreateTimer(callback, source = new(), remainingTime, InfiniteTimeSpan); @@ -146,14 +146,14 @@ public async ValueTask TryRenewAsync(CancellationToken token = default) if (identity.Version is LeaseIdentity.InitialVersion) throw new InvalidOperationException(); - var ts = new Timestamp(); + var ts = new Timestamp(provider); if (await TryRenewCoreAsync(identity, token).ConfigureAwait(false) is { } response) { identity = response.Identity; // ensure that the timer has been stopped await timer.DisposeAsync().ConfigureAwait(false); - var remainingTime = AdjustTimeToLive(response.TimeToLive) - ts.Elapsed; + var remainingTime = AdjustTimeToLive(response.TimeToLive) - ts.GetElapsedTime(provider); if (remainingTime > TimeSpan.Zero) { diff --git a/src/DotNext.Threading/Threading/Leases/LeaseProvider.cs b/src/DotNext.Threading/Threading/Leases/LeaseProvider.cs index f828284a1..69fbe608b 100644 --- a/src/DotNext.Threading/Threading/Leases/LeaseProvider.cs +++ b/src/DotNext.Threading/Threading/Leases/LeaseProvider.cs @@ -70,11 +70,11 @@ protected LeaseProvider(TimeSpan ttl, TimeProvider? provider = null) Metadata = await updater.Invoke(state.Metadata, token).ConfigureAwait(false), }; - var ts = new Timestamp(); + var ts = new Timestamp(provider); if (!await TryUpdateStateAsync(state, token).ConfigureAwait(false)) return null; - remainingTime = TimeToLive - ts.Elapsed; + remainingTime = TimeToLive - ts.GetElapsedTime(provider); return remainingTime > TimeSpan.Zero ? new(in state, remainingTime) : null; @@ -132,11 +132,11 @@ private async ValueTask AcquireAsync(TUpdater updat Metadata = await updater.Invoke(state.Metadata, token).ConfigureAwait(false), }; - var ts = new Timestamp(); + var ts = new Timestamp(provider); if (!await TryUpdateStateAsync(state, token).ConfigureAwait(false)) continue; - remainingTime = TimeToLive - ts.Elapsed; + remainingTime = TimeToLive - ts.GetElapsedTime(provider); if (remainingTime <= TimeSpan.Zero) continue;