Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Means of waking up the event loop #42

Open
SirVer opened this issue Aug 17, 2015 · 2 comments
Open

Means of waking up the event loop #42

SirVer opened this issue Aug 17, 2015 · 2 comments

Comments

@SirVer
Copy link

SirVer commented Aug 17, 2015

Right now, rustbox blocks in poll_event and there is no way of waking it up. An external event in another thread does not seem to have any means of triggering a redraw without using peek_event in a busy loop.

I think a cleaner design would be to replace poll_event through a mpsc::channel. The consumer could then select over multiple channels to act on multiple inputs and peek_event could just be idiomatically replaced through https://doc.rust-lang.org/nightly/std/iter/struct.Peekable.html. This would also allow for the very intuitive for loop syntax:

// rustbox.events is a mpsc::Receiver<rustbox::Event>;
while let (event) = rustbox.events {
match event {
....
}
}
@SirVer
Copy link
Author

SirVer commented Aug 17, 2015

Another solution would be to add a thread-safe rustbox::wakeup() that would fire a wakeup event, so other threads could force a redraw.

@droundy
Copy link

droundy commented Sep 11, 2015

I'll add to this that I really like the idea of using a channel for the event stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants