TimeProviderTaskExtensions
Provides extensions methods for Task operations with TimeProvider.
using System.Runtime.CompilerServices;
namespace System.Threading.Tasks
{
[NullableContext(1)]
[Nullable(0)]
public static class TimeProviderTaskExtensions
{
public static Task Delay(this TimeProvider timeProvider, TimeSpan delay, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.Delay(delay, timeProvider, cancellationToken);
}
public static Task WaitAsync(this Task task, TimeSpan timeout, TimeProvider timeProvider, CancellationToken cancellationToken = default(CancellationToken))
{
return task.WaitAsync(timeout, timeProvider, cancellationToken);
}
public static Task<TResult> WaitAsync<[Nullable(2)] TResult>(this Task<TResult> task, TimeSpan timeout, TimeProvider timeProvider, CancellationToken cancellationToken = default(CancellationToken))
{
return task.WaitAsync(timeout, timeProvider, cancellationToken);
}
public static CancellationTokenSource CreateCancellationTokenSource(this TimeProvider timeProvider, TimeSpan delay)
{
return new CancellationTokenSource(delay, timeProvider);
}
}
}