diff --git a/src/DotNext.Tests/Threading/Leases/LeaseTests.cs b/src/DotNext.Tests/Threading/Leases/LeaseTests.cs index 5adf162db..786319e3d 100644 --- a/src/DotNext.Tests/Threading/Leases/LeaseTests.cs +++ b/src/DotNext.Tests/Threading/Leases/LeaseTests.cs @@ -90,7 +90,8 @@ public static async Task ConsumerTokenState() True(consumer.Token.IsCancellationRequested); True(consumer.Expiration.IsExpired); - True((await consumer.TryAcquireAsync())); + True(await consumer.TryAcquireAsync()); + Equal(1UL, consumer.LeaseId.Version); False(consumer.Token.IsCancellationRequested); False(consumer.Expiration.IsExpired); diff --git a/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs b/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs index c36a92a16..0f23bb4d6 100644 --- a/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs +++ b/src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs @@ -78,6 +78,12 @@ private TimeSpan AdjustTimeToLive(TimeSpan originalTtl) /// Gets lease expiration timeout. /// public ref readonly Timeout Expiration => ref timeout; + + /// + /// Gets the lease version. + /// + /// The returned value can be used as a fencing token. + public LeaseIdentity LeaseId => identity; private ValueTask CancelAndStopTimerAsync() { @@ -181,7 +187,7 @@ public async Task ExecuteAsync(Func ExecuteAsync(Func Fork(Func> function, CancellationToken token) - => Task.Run(() => function(token), token); + static Task Fork(Func> function, CancellationToken token) + => Task.Run(() => function(token), token); + } /// /// Performs a call to across the application boundaries.