void (long nowNano) { synchronized (myLock) { if (myPendingChunks.isEmpty()) { // There could be no pending chunks in the following case: // When pending chunks were processed for the first time, another stream didn't end with a newline => the chunks were re-scheduled. // Then, another stream got a newline => the pending chunks were processed immediately. myReschedules = 0; return; } // All pending chunks should have the same base output type (`chunk.myBaseOutputType`). Chunk eldestChunk = myPendingChunks.get(0); long awaitNano = eldestChunk.getNanoTimePassedSinceLastFlushedChunk(nowNano); if ((awaitNano >= AWAIT_SAME_STREAM_TEXT_NANO && myFlushedChunksEndWithNewline) || myReschedules > (isUnitTestMode ? 10 : 1)) { flushAllPendingChunks(); } if (!myPendingChunks.isEmpty()) { myReschedules++; scheduleProcessPendingChunks(AWAIT_SAME_STREAM_TEXT_NANO); } else { myReschedules = 0; } } }