Overload nonblock semantics with a timeout value #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Useful if you have an application that would like to sleep at the end
of every loop. This will let it wait for & collect the keypress until the
sleep would have expired.
For example, this loop will sleep until approximately the start of the next
second on the system clock.
Describe the change
Overload the semantics of the
nonblockso that it can take atimeoutvalue as well asBoolean.Why are we doing this?
I'm building an application that is like
top: It updates the terminal screen at 1 second intervals, andneeds to listen to keyboard commands. I was having trouble capturing the key presses in my event loop.
I had a
sleepin the loop, but then I noticed thatConsole#get_char# has aTIMEOUT` constant.Benefits
This adds a useful feature for writing looping applications.
Drawbacks
Not supported in
win_console.This may not be the best approach for this type of application. I did a bunch of experimentation before I
got this to work to my satisfaction.
There are no tests around the
nonblockoption, and I'm not sure how to test a timeout option withoutintroducing something like the
Timecopgem to the development environment.Requirements
masterbranch?