bj0
11/15/2024, 10:00 PMResource
api question: I have a function that gets called to start a udp receiver and send received data to a listener, and normally i would think to do something similar to:
override fun start(port) {
scope.launch {
flow {
resourceScope {
val socket = closeable { DatagramSocket(port) }
emit(socket.receive())
}
}.collect(::listener)
}
}
but I want to be able to catch the initial socket exceptions from creating DatagramSocket
inside start
while still launching the receiving on a coroutine. can I do this and still use the resource api? i don't control the interface with start
or the caller