1. interrupable sleep

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.

include std/types.e
 
function heDidNotWait(integer Seconds) 
  for i = 1 to Seconds do 
    if isInterrupted() then 
      return TRUE 
    end if 
  end for 
  return FALSE 
end function

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?

new topic     » topic index » view message » categorize

2. Re: interrupable sleep

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. sad Where does isInterrupted() come from?

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: interrupable sleep

ghaberek said...
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().

I think what is really wanted is an implementation for isInterrupted().

ghaberek said...
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. sad

-Greg

I think it means: if the cursor of the mouse was moved.

new topic     » goto parent     » topic index » view message » categorize

4. Re: interrupable sleep

jimcbrown said...

I think what is really wanted is an implementation for isInterrupted().

I think it means: if the cursor of the mouse was moved.

You may want GetLastInputInfo

Pete

new topic     » goto parent     » topic index » view message » categorize

5. Re: interrupable sleep

ghaberek said...
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. sad

-Greg

I mean rotation of wheel between mouse's buttons. Sorry for my poor english.

new topic     » goto parent     » topic index » view message » categorize

6. Re: interrupable sleep

SnakeCharmer said...
ghaberek said...
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. sad

I mean rotation of wheel between mouse's buttons. Sorry for my poor english.

What sort of a program is this? Assuming you're using some GUI library, then I'd say that you'd set a timer or something, and invalidate or destroy it if you get a scroll wheel event in the meantime. If this is a console type program, that isn't using some event system, then you'll just have to periodically poll the scroll wheel.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu