mplatvoet
05/06/2016, 7:06 AMContext for io since that tends to block, so something like this:
val ioContext = Kovenant.createContext {
workerContext.dispatcher = buildDispatcher {
concurrentTasks = 2 //whatever you prefer
}
//Use the default one
callbackContext.dispatcher = Kovenant.context.callbackContext.dispatcher
}
fun <V> ioTask(body: () -> V) : Promise<V, Exception> {
//execute the task on the io threads
val promise = task(ioContext, body)
//use default context for the rest of the work
return promise.withContext(Kovenant.context)
}
fun main(args: Array<String>) {
ioTask {
File("path/to/file").readText()
} then {
it.replace(":)", "☺")
} success {
println(it)
}
}