try {
if (batching.compareAndSet(false, true)) {
try {
Future result = null;
if (nextWriteBatch != null) {
result = new WriteFuture(nextWriteBatch.getLatch());
batchQueue.offer(nextWriteBatch);
signalBatch();
nextWriteBatch = null;
} else {
result = new WriteFuture(journal.getLastAppendLocation().getLatch());
}
return result;
} finally {
batching.set(false);
}