Ryan Smith
01/10/2023, 12:28 AMDatagramSocket as internal state and implements Runnable so it can be scheduled to run in the background on a ThreadPoolExecutor. Right now this class polls every so often to check a concurrent queue for messages to send and other application code uses some send methods on it to add messages to the queue for sending.
Conceptually I think I need the following ingredients to port this to coroutines:
1. newSingleThreadContext
2. runBlocking { } on that single thread context to get it started
3. A SendChannel for other code to interact with to actually send
4. delay(POLL_INTERVAL) for polling (although, I'm not sure I actually need this if I use RENDEZVOUS)
Is this ingredients list sound? Is there anything that jumps out at you as unnecessary or even missing? From what I've read I could probably lump most of this together with actor, but that has been marked ObsoleteCoroutineApi so I'll probably stay away from it for now.
Whatever I end up doing for Tx I hope to repurpose as much as possible for Rx where Ill have some additional complexity around pushing messages out to other application code (probably using a SharedFlow).
I'd appreciate any thoughts, and if you know of any examples of this sort of thing I'd appreciate that as well. ktor comes to mind as having a lot of socket related code + coroutine support, but it would be a pretty big dependency to include just for the socket APIs.franztesca
01/10/2023, 10:46 AMRyan Smith
01/11/2023, 12:01 AMdelay, I'm still learning my way around so it. It looks like BUFFERED, with onBufferOverflow = BufferOverflRyan Smith
02/18/2023, 3:38 PMBlockingQueue for Tx and relies on Socket::receive 's inherent "block until something is available" behavior to do what you described here for a coroutines implementation. Should make for a very straight forward translation to coroutines.