IO
Real, possibly asynchronous, I/O. A handler that needs it translates its effects into performIO binds, and one suspend runner at the edge, io or on the JVM ioBlocking(), runs them all:
fun <A> Program<A>.consoleAsync(): Program<A> =
handle<Console<*>, A> { op ->
when (op) {
is Print -> performIO { sendToRemoteLog(op.line) }.bind()
ReadLine -> performIO { fetchInputFromApi() }.bind()
}
}
val name = greeter.consoleAsync().io()Content copied to clipboard