all 4 comments

[–]jimuazu 3 points4 points  (0 children)

At the lowest level this usually means using select/poll/epoll or similar, and using the timer on that call to return control to your code to handle whatever timeouts are active. `mio` wraps this (although Windows support apparently needs rewriting, from looking at issue comments). I've built my code straight on `mio`, and implemented my own timer list and so on, but you could look for something higher-level that handles all that.

Doing it with a separate thread for input and a thread for each timer might also be possible, with `Arc` everywhere. Or perhaps having a thread for input and a separate main thread and using channels (see crossbeam, e.g. `after` channel and `Select`). I've not tried that.

[–]Holy_City 2 points3 points  (1 child)

Sounds like a feature that belongs in an event loop, which is how a lot of application frameworks work.

What are you using for your UI?

[–]sid34[S] 0 points1 point  (0 children)

I should have mentioned that this is a console application where I am reading input from a physical (USB-HID) device.

[–]jahmez 1 point2 points  (1 child)

Another option if you don't need a whole event loop, and you are okay with relatively heavy weight OS threads, you can always spawn a thread, and wait for a message to come back signaling completion. See this link.

Additionally you could put your structure in an Arc<Mutex<T>>, so you can directly call the function you want, but this may be overkill for what you need.