in Confidence/src/main/java/com/spotify/confidence/apply/EventProcessor.kt [37:72]
fun start() {
coroutineScope.launch {
// the data being in a coroutine like this
// ensures we don't have any shared mutability
val data: DATA = onInitialised()
// Try send events retrieved via "onInitialised()"
onProcessBatch(
data,
dataSentChannel,
coroutineScope,
exceptionHandler
)
// the select clause makes sure that we don't
// share the data/file write operations between coroutines
// at any certain time there is only one of these events being handled
while (true) {
select {
writeRequestChannel.onReceive { writeRequest ->
onApply(writeRequest, data)
onProcessBatch(
data,
dataSentChannel,
coroutineScope,
exceptionHandler
)
}
dataSentChannel.onReceive { event ->
processBatchAction(event, data)
}
}
}
}
}