> particularly about receiving events from channels on the async side? Using 
> the polling method seems the most obvious but not ideal

Channels and async use different kernel concurrency mechanisms and aren't 
comptible. What you need when using async are network based event loop 
mechanism. In Nim this is 
[newSelectEvent](https://github.com/nim-lang/Nim/blob/ed7c6cdc984b12a30a44344167083ec0dc46cf9a/lib/pure/ioselects/ioselectors_poll.nim#L192).
 It looks like asyncnet stuff wraps them with 
[newSelectEvent](https://github.com/nim-lang/Nim/blob/064ed4846d0579f029926cdda7ecc387679b4e65/lib/pure/asyncdispatch.nim#L1617).

Using `SelectEvent/AsyncSelectEvent` is pretty efficient and uses the kernel 
select/poll but the Nim api doesn't let you pass data. So you need to combine 
them with a channel or queue separately. The core idea is to put data into a 
queue and then send a notification via `SelectEvent` that data is available. 
The receiver will be woken up and can get the data.

A while back I made some 
[inettypes](https://github.com/EmbeddedNim/mcu_utils/blob/main/src/mcu_utils/inettypes.nim)
 and 
[inetqueues](https://github.com/EmbeddedNim/mcu_utils/blob/699a4aa077126f82b207657b63e43483519006ee/src/mcu_utils/inetqueues.nim#L92)
 that do this for non-async. You can probably find some ideas from them, or 
perhaps tweak them to be async.

Reply via email to