rebuild

suspend fun <T : Any> rebuild(ref: AggregateRef, streams: Int, replay: suspend () -> T): T?

Runs replay, a reader's rebuild of ref's state that reads streams streams of its log, and returns what it gives, unless another reader's rebuild of ref runs already: then it waits for that one to end, however it ends, and returns null, so the caller looks again for the view that rebuild left, and rebuilds itself only without one. A rebuild that fails, is cancelled or is refused by the gate ends like one that succeeds: one of the readers that waited for it rebuilds next, and the others wait for that one; none fails with it.

A wait is cancellable: a reader's own timeout, or the end of its lane, ends it, not the rebuild it waits for.

A replay of more than one page (VersionPages.SIZE streams) runs under the gate, which may make it wait for a permit, or refuse it; one of a page or less runs at once.