Innovenergy_trunk/csharp/Lib/Utils/Try/Policy.cs

34 lines
773 B
C#

namespace InnovEnergy.Lib.Utils.Try;
[Obsolete]
public static class Policy
{
internal static Random Rng { get; } = new Random();
internal static TimeSpan ApplyJitter(this TimeSpan timeSpan, Double ratio)
{
return timeSpan * (1 - ratio + Rng.NextDouble() * 2 * ratio);
}
public static TrySync<R> Try<R>(Func<R> func)
{
return new TrySync<R>(func);
}
public static TrySync<R> TryApply<T,R>(this T t, Func<T, R> func)
{
return new TrySync<R>(() => func(t));
}
public static TryAsync<R> Try<R>(Func<Task<R>> func)
{
return new TryAsync<R>(func);
}
public static TryAsync<R> TryApply<T,R>(this T t, Func<T, Task<R>> func)
{
return new TryAsync<R>(() => func(t));
}
}