make sure all batches are consumed before the input thread signals termination