TaskHelpers
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace System.Reactive.Concurrency
{
    [System.Runtime.CompilerServices.NullableContext(1)]
    [System.Runtime.CompilerServices.Nullable(0)]
    internal static class TaskHelpers
    {
        private const int MaxDelay = int.MaxValue;
        public static Task Delay(TimeSpan delay, CancellationToken token)
        {
            if ((long)delay.TotalMilliseconds > 2147483647) {
                TimeSpan remainder = delay - TimeSpan.FromMilliseconds(2147483647);
                return Task.Delay(2147483647, token).ContinueWith((Task _) => Delay(remainder, token), TaskContinuationOptions.ExecuteSynchronously).Unwrap();
            }
            return Task.Delay(delay, token);
        }
        public static Exception GetSingleException(this Task t)
        {
            if (t.Exception.InnerException != null)
                return t.Exception.InnerException;
            return t.Exception;
        }
    }
}