I am building a protocol (trying to emulate something, so I have to stick to the specs) that is UDP based but on top of UDP, they somehow emulate something like TCP with sequence numbers and the like.
For now everything is tokio and async await based (although I am open to suggestions here). I am trying to find an idiomatic pattern to have the listening loop working in the "background" (actually multiple listening loops on top of each other regarding the layers of the protocol).
The first level that I came up with is this: https://gist.github.com/anarelion/d62c01e723403f0d2e64dda5063a3dda
Is this idiomatic? Is there any better way? I don't like how it forces me to lock the connection and timeout every now and then so others can have the chance to lock it and see if there is any packet available.