Class AsyncSemaphore<T>


  • @ThreadSafe
    public class AsyncSemaphore<T>
    extends Object
    Guarantees that no more than maxPermits of tasks will be run concurrently. The class will rely on the ListenableFuture returned by the submitter function to determine when a task has been completed. The submitter function NEEDS to be thread-safe and is recommended to do the bulk of its work asynchronously.
    • Constructor Detail

      • AsyncSemaphore

        public AsyncSemaphore​(int maxPermits,
                              Executor submitExecutor,
                              Function<T,​com.google.common.util.concurrent.ListenableFuture<?>> submitter)
    • Method Detail

      • submit

        public com.google.common.util.concurrent.ListenableFuture<Void> submit​(T task)