commonMain.MemoryAggregateStore.kt Maven / Gradle / Ivy
The newest version!
package io.fluidsonic.raptor.domain.memory
import io.fluidsonic.raptor.domain.*
import io.fluidsonic.time.Timestamp
import kotlinx.coroutines.flow.*
// FIXME Prevent race conditions.
// FIXME Check for version conflicts.
private class MemoryAggregateStore : RaptorAggregateStore {
private val events: MutableList> = mutableListOf()
override suspend fun add(events: List>) {
this.events += events
}
override suspend fun lastEventTimestampOrNull(): Timestamp? =
events.lastOrNull()?.timestamp
override fun load(after: RaptorAggregateEventId?) =
events
.let { events ->
when (after) {
null -> events.toList()
else -> events.filter { it.id > after }
}
}
.asFlow()
}
public fun RaptorAggregateStore.Companion.memory(): RaptorAggregateStore =
MemoryAggregateStore()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy