Websockets
Common code
suspend (ReceiveChannel<M>, SendChannel<N>) -> Unit
suspend (suspend (SendChannel<M>, ReceiveChannel<N>) -> Unit) -> Unitinterface IWsService {
suspend fun wservice(input: ReceiveChannel<Int>, output: SendChannel<String>) {}
suspend fun wservice(handler: suspend (SendChannel<Int>, ReceiveChannel<String>) -> Unit) {}
}Frontend application
val ws = getService<IWsService>()
GlobalScope.launch {
ws.wsservice { output /*: SendChannel<Int>*/, input /*: ReceiveChannel<String>*/ ->
coroutineScope {
launch {
while(true) {
val i = Random.nextInt()
output.send(i)
delay(1000)
}
}
launch {
for (str in input) {
println(str)
}
}
}
}
}