Module iu.util
Package edu.iu

Class IuRateLimitter

java.lang.Object
edu.iu.IuRateLimitter
All Implemented Interfaces:
IuTaskController, UnsafeConsumer<IuTaskController>

public class IuRateLimitter extends Object implements UnsafeConsumer<IuTaskController>, IuTaskController
Unifies control over a bounded queue of controlled tasks.

This rate limiter is fail-fast. All tasks are expected to complete normally without error. The first error or timeout condition should be thrown when the controlling process reaches its next blocking operation.

Once a fixed limit on incomplete tasks has been reached, new tasks cannot be accepted without first removing and joining the task at the head of the queue. Once any task has timed out or produced an error, any attempt to accept(IuTaskController) or join() will throw that error. Additional errors encountered after the first error will be suppressed.

 final var limit = new IuRateLimitter(10, Duration.ofSeconds(1L));
 for (UnsafeRunnable task : tasks)
        limit.accept(workload.accept(task));
 limit.join();