public Request(InterReactClientConnector builder, IRxSocketClient rxSocket) { Builder = builder; Limiter = new RingLimiter(Builder.MaxRequestsPerSecond); ArgumentNullException.ThrowIfNull(rxSocket); RxSocket = rxSocket; }
public double Limit(int rate, double duration) { var limiter = new RingLimiter(Logger, rate); var count = 0; var start = Stopwatch.GetTimestamp(); while (((Stopwatch.GetTimestamp() - start) / (double)Stopwatch.Frequency) < duration) { limiter.Limit(() => Thread.Sleep(1)); count++; } var time = (Stopwatch.GetTimestamp() - start) / (double)Stopwatch.Frequency; var freq = count / time; Logger.LogInformation("{Count} / {Time} => {Freq} ({Rate})", count, time, freq, rate); return(freq); }