public CompletableFuture < Queue < T > > take ( int maxCount ) { synchronized ( this . contents ) { Exceptions . checkNotClosed ( this . closed , this ) ; Preconditions . checkState ( this . pendingTake == null , "Cannot have more than one concurrent pending take() request." ) ; Queue < T > result = fetch ( maxCount ) ; if ( result . size ( ) > 0 ) { return CompletableFuture . completedFuture ( result ) ; } else { this . pendingTake = new CompletableFuture <> ( ) ; return this . pendingTake ; } } }
Returns the next items from the queue . If the queue is empty it blocks the call until at least one item is added .