Asyncdispatch supports timers and I think that's all you need for UI events, right? This is exposed via the sleepAsync procedure. But keep in mind that currently the timers are processed after the call to epoll/kqueue/iocp so if you call poll(5000) (with a timeout of 5 seconds) the timers may only be processed after 5 seconds.
There might be a better way to handle them, ideas/PRs welcome :)
As for JS support, I think it should be possible just need to write a couple of when defined(js) in the asyncdispatch module.
Asyncdispatch supports timers and I think that's all you need for UI events, right? This is exposed via the sleepAsync procedure. But keep in mind that currently the timers are processed after the call to epoll/kqueue/iocp so if you call poll(5000) (with a timeout of 5 seconds) the timers may only be processed after 5 seconds.
TBH I can't see how timers are of any use here. Take MacOS/iOS for example. All the magic happens in CFRunloopRun(), which waits on mach_port_t set for ui events. AFAIK other IO events are awaited (by using select or smth similar) for in a separate thread, that in its turn reposts mach events to the appropriate CFRunloop. So my point is, the overall architecture of a cross-platform runloop that supports ui events is the following:
1. For every platform there should be an implementation of its native runloop, that:
- Waits for native platform events including ui. On Mac/iOS that should be CFRunLoop.
- Supports sending custom events to it from a different thread. We might call it a runloop source. Signalling a runloop source will break the loop it is registered in and make it perform the source's callback on the thread of runloop.
- Arguably it may support timers right in its thread using binary heaps and wait timeouts, or it may delegate timers management to a separate thread (afaik thats what SDL does). In the latter case it would be a cross-platform runloop source implementation.
As for JS support, I think it should be possible just need to write a couple of when defined(js) in the asyncdispatch module.
I'm still having a hard time understanding all the async/await magic. I would appreciate some documentation of what does async/await macros do, how the AST gets transformed, etc. I would really love a link to such details in the syncdispatch module docs ;)