Re: interrupable sleep
- Posted by ghaberek (admin) Dec 31, 2012
- 1297 views
SnakeCharmer said...
I need a function, that sleep for some seconds. Waiting can be interrupted with the action. In such case that function has to return TRUE.
This should do the trick. Just replace my get_key() with your isInterrupted().
include "std/os.e" public function wait( atom t ) atom stop_time = time() + t while time() < stop_time do if get_key() != -1 then return 1 -- TRUE end if -- pause sleep(0) end while return 0 -- FALSE end function -- testing puts( 1, "waiting..." ) wait( 30 ) -- can be canceled by a key press puts( 1, "done!\n" )
SnakeCharmer said...
By the way, function isInterrupted has to return TRUE, if the castor of a mouse was turned. How to do it? Perhaps to reconstruct function?
I have no idea what you mean by this. Where does isInterrupted() come from?
-Greg