Kenton Varda wrote:
> If you wanted to hack it using a thread, have the thread periodically
> write a byte to a pipe, and in your main thread wait on the read end of
> the pipe. In fact, AsyncIoProvider has a method newPipeThread() which
> should make this easy to set up.
>
> In this other thread, you can feel free to use wait() and sleep(), as
> the thread will not need to be actively listening for any kind of event.
Right, I hadn't thought of that. Thanks for the suggestion.
> Alternatively if you want to go through and add a timer queue to
> UnixEventPort, that would be cool. :)
Sure, why not. I have found the place where poll() is called, so that's
probably where I should plug in a list (or a heap) of timers and set the
timeout to the time until the next timer expires. Where I'm not so sure
is how to pipe the timer functionality through to higher levels.
I suppose it would make sense to expose the timer functionality in
EventLoop, something like:
typedef int64_t Time; // Microseconds since the epoch
Time now() const;
Promise<void> setTimer(Time time);
I see that EventLoop is owned by the LowLevelAsyncIoProviderImpl, but
isn't made accessible. And AsyncIoContext only has a WaitScope. Should
it have a reference to EventLoop instead (and users can create their own
WaitScope on the stack)?
It would be great if you could give me a few hints about how you imagine
this should be implemented, so that I don't go off too far in the wrong
direction.
-- Remy