Skip to content

Instantly share code, notes, and snippets.

@xrrocha
Created May 8, 2022 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xrrocha/2ebc95b26b014fa540d1e81092ea8214 to your computer and use it in GitHub Desktop.
Save xrrocha/2ebc95b26b014fa540d1e81092ea8214 to your computer and use it in GitHub Desktop.
// Skeletal Kotlin TL;DR for the truly impatient:
class MemoryImageProcessor(private val system: Any,
private val eventSourcing: EventSourcing) {
init {
synchronized(this) {
eventSourcing.replay<Command> { command -> command.applyTo(system) }
}
}
fun execute(command: Command): Unit = synchronized(this) {
TxManager.begin()
try {
command.applyTo(system)
eventSourcing.append(command)
} catch (e: Exception) {
TxManager.rollback()
throw e
}
}
fun execute(query: Query): Any? = query.extractFrom(system)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment