private async Task Test_WaitForReadiness_LimitIsBasedOnCount(int count, IAwaitableConstraint countByIntervalAwaitableConstraint) { for (var i = 0; i < count; i++) { await SetUpSaturated(countByIntervalAwaitableConstraint); } }
public static IAwaitableConstraint Compose(this IAwaitableConstraint ac1, IAwaitableConstraint ac2) { if (ac1 == ac2) { return(ac1); } return(new ComposedAwaitableConstraint(ac1, ac2)); }
public void RemoveRateLimit(IAwaitableConstraint constraint) { if (constraint == null) { throw new ArgumentException("You must supply a valid constraint", nameof(constraint)); } this.timeLimiters.Remove(constraint); }
/// <summary> /// Compose two awaitable constraint in a new one /// </summary> /// <param name="awaitableConstraint1"></param> /// <param name="awaitableConstraint2"></param> /// <returns></returns> public static IAwaitableConstraint Compose(this IAwaitableConstraint awaitableConstraint1, IAwaitableConstraint awaitableConstraint2) { if (awaitableConstraint1 == awaitableConstraint2) { return(awaitableConstraint1); } return(new ComposedAwaitableConstraint(awaitableConstraint1, awaitableConstraint2)); }
public RateLimiterTest() { _FuncTask = Substitute.For <Func <Task> >(); _FuncTaskInt = Substitute.For <Func <Task <int> > >(); _IAwaitableConstraint = Substitute.For <IAwaitableConstraint>(); _Diposable = Substitute.For <IDisposable>(); _IAwaitableConstraint.WaitForReadiness(Arg.Any <CancellationToken>()).Returns(Task.FromResult(_Diposable)); _TimeConstraint = new RateLimiter.TimeLimiter(_IAwaitableConstraint); }
public static TimeLimiter Compose(params IAwaitableConstraint[] constraints) { IAwaitableConstraint current = null; foreach (var constraint in constraints) { current = (current == null) ? constraint : current.Compose(constraint); } return(new TimeLimiter(current)); }
public AwaitableConstraintExtensionTests() { _AwaitableConstraint1 = Substitute.For <IAwaitableConstraint>(); _AwaitableConstraint2 = Substitute.For <IAwaitableConstraint>(); _Disposable1 = Substitute.For <IDisposable>(); _Disposable2 = Substitute.For <IDisposable>(); _AwaitableConstraint1.WaitForReadiness(Arg.Any <CancellationToken>()).Returns(Task.FromResult(_Disposable1)); _AwaitableConstraint2.WaitForReadiness(Arg.Any <CancellationToken>()).Returns(Task.FromResult(_Disposable2)); _Composed = _AwaitableConstraint1.Compose(_AwaitableConstraint2); }
public ComposedAwaitableConstraintTest() { _IAwaitableConstraint1 = Substitute.For <IAwaitableConstraint>(); _IAwaitableConstraint2 = Substitute.For <IAwaitableConstraint>(); _Diposable1 = Substitute.For <IDisposable>(); _Diposable2 = Substitute.For <IDisposable>(); _IAwaitableConstraint1.WaitForReadiness(Arg.Any <CancellationToken>()).Returns(Task.FromResult(_Diposable1)); _IAwaitableConstraint2.WaitForReadiness(Arg.Any <CancellationToken>()).Returns(Task.FromResult(_Diposable2)); _Composed = new ComposedAwaitableConstraint(_IAwaitableConstraint1, _IAwaitableConstraint2); }
internal ComposedAwaitableConstraint(IAwaitableConstraint awaitableConstraint1, IAwaitableConstraint awaitableConstraint2) { _AwaitableConstraint1 = awaitableConstraint1; _AwaitableConstraint2 = awaitableConstraint2; }
internal ComposedAwaitableConstraint(IAwaitableConstraint ac1, IAwaitableConstraint ac2) { _ac1 = ac1; _ac2 = ac2; }
internal TimeLimiter(IAwaitableConstraint awaitableConstraint) { _AwaitableConstraint = awaitableConstraint; }
/// <summary> /// Construct an RateLimiterDispatcher from an <see cref="IAwaitableConstraint"/> /// </summary> /// <param name="awaitableConstraint"></param> public RateLimiterDispatcher(IAwaitableConstraint awaitableConstraint) { _AwaitableConstraint = awaitableConstraint; }
internal TimeLimiter(IAwaitableConstraint ac) { _ac = ac; }
private static async Task SetUpSaturated(IAwaitableConstraint countByIntervalAwaitableConstraint) { using (await countByIntervalAwaitableConstraint.WaitForReadiness(CancellationToken.None)) { } }