executeBatch

suspend fun <S : Any> executeBatch(model: AggregateModel<S>, queued: List<QueuedCommand>, appending: (EventStreamRecord, CachedState) -> Unit? = null): List<BatchOutcome>

Executes queued, commands of one aggregate in arrival order, deciding each on the state the ones before it left and appending their streams with one EventLog.appendAll: the aggregate's commands are committed together instead of one append each. Each command's outcome is what execute would have given it.

The first command always runs, alone through execute when it cannot start a batch. A batch takes the commands after it while each one is pure (its decide function and after hooks do no I/O, so deciding it again costs nothing), is not sent for a schedule, is not among the aggregate's recent requests or the batch's own, and appends a stream; it ends before the first that is not, which is BatchOutcome.Again: the lane runs it next, alone if need be. The streams commit as a prefix (EventLog.appendAll); the first that does not commit is settled as execute settles an append, and the commands after it, compensated, are BatchOutcome.Again: their streams were decided on a state that did not commit. The aggregate's state is then dropped from the cache, as a later stream evolved it.