when using callbackFlow I need to clean up resources but when the job is canceled awaitClose isn't being called. How do I invoke awaitClose on a cancellation of the job
Copy code
fun listen(port: Int = 1337, nThreads: Int = 2) = callbackFlow<String> {
val ch = b.bind(port).coAwait { }
for (obj in coReceiveChannel) {
send(obj)
}
awaitClose {
coReceiveChannel.cancel()
ch.close()
}
} // end of listen
job = listen().onEach { println(it) }.launchIn(scope)
job.cancel() // doesn't call awaitClose