william
10/23/2020, 12:34 PMclass PersistentWsClient() {
private val scope = CoroutineScope(Dispatchers.Default)
private val sendingQueue = Channel<Frame>(UNLIMITED)
fun open(host: String, path: String, port: Int = 8080) {
scope.launch {
this@PersistentWsClient.e("waiting for messages")
for (msg in sendingQueue) {
this@PersistentWsClient.e(msg.toString())
}
}
}
fun send(payload: Frame) {
scope.launch {
for (i in 0..10) {
delay(500)
sendingQueue.offer(payload)
this.e("offering $payload")
}
}
sendingQueue.offer(payload)
}
}
(i have stripped away some extra code).
In this example i only ever get
waiting for messages
offering <payload>
offering <payload>
...
i posted in #coroutines as well but haven't had any help there yet