Created
May 8, 2022 23:47
-
-
Save xrrocha/2ebc95b26b014fa540d1e81092ea8214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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