private synchronized void tryDrainNextWaiting(final boolean force){
  final Pair<CompletableFuture<List<Result>>,Integer> nextWaiting=waiting.peek();
  if (nextWaiting != null && (force || (resultLinkedBlockingQueue.size() >= nextWaiting.getValue1() || readComplete.isDone()))) {
    final int items=nextWaiting.getValue1();
    final CompletableFuture<List<Result>> future=nextWaiting.getValue0();
    final List<Result> results=new ArrayList<>(items);
    resultLinkedBlockingQueue.drainTo(results,items);
    if (null == error.get())     future.complete(results);
 else     future.completeExceptionally(error.get());
    waiting.remove(nextWaiting);
  }
}

private synchronized void tryDrainNextWaiting ( final boolean force ) { final Pair < CompletableFuture < List < Result > > , Integer > nextWaiting = waiting . peek ( ) ; if ( nextWaiting != null && ( force || ( resultLinkedBlockingQueue . size ( ) >= nextWaiting . getValue1 ( ) || readComplete . isDone ( ) ) ) ) { final int items = nextWaiting . getValue1 ( ) ; final CompletableFuture < List < Result > > future = nextWaiting . getValue0 ( ) ; final List < Result > results = new ArrayList < > ( items ) ; resultLinkedBlockingQueue . drainTo ( results , items ) ; if ( null == error . get ( ) ) future . complete ( results ) ; else future . completeExceptionally ( error . get ( ) ) ; waiting . remove ( nextWaiting ) ; } }
completes the next waiting future if there is one .
