namespace RioJoy.Core.Tests;
///
/// net48 test-only polyfills. Visible to all tests via enclosing-namespace scope.
///
internal static class TaskTestExtensions
{
///
/// Polyfill for Task<T>.WaitAsync(TimeSpan) (net6+), absent on net48.
/// Throws if the task does not complete in time.
///
public static async Task WaitAsync(this Task task, TimeSpan timeout)
{
using var cts = new CancellationTokenSource();
Task completed = await Task.WhenAny(task, Task.Delay(timeout, cts.Token)).ConfigureAwait(false);
if (completed != task)
throw new TimeoutException($"Task did not complete within {timeout}.");
cts.Cancel(); // stop the delay timer
return await task.ConfigureAwait(false);
}
}