Start / Stop timer

124 views
Skip to first unread message

rric...@itspokernight.com

unread,
Feb 19, 2012, 8:39:31 AM2/19/12
to rhomobile
So I'm trying to use the Timer (http://rhodesapi.rhomobile.com/timer-
api) to implement a "delay" in between executing functions. The
Rho::Timer.Start() works fine, but I just want to STOP the timer after
the callback specified in the Start method has fired. I don't need a
callback in the stop function, just need the timer not to fire again.
I incorrectly assumed I could use Rho::Timer.stop() but it thinks that
I want to implement a null callback. Other than giving it a "dummy"
method to call, which would do nothing, is there any other way to turn
off the timer?

Jon Tara

unread,
Feb 19, 2012, 12:06:03 PM2/19/12
to rhom...@googlegroups.com
There's no need to stop the timer in this case. When you get the callback, the timer has timed-out. It's already stopped. It's a one-shot timer, not a repeat interval timer.

You only need to stop the timer of you want to cancel it - i.e. you no longer want the callback to occur.

You can stop the timer with Rho::Timer.stop(url)

http://docs.rhomobile.com/rhodes/device-caps#timer

Jon Tara

unread,
Feb 19, 2012, 12:06:42 PM2/19/12
to rhom...@googlegroups.com
If you are getting multiple calls to the callback, you must be starting the timer multiple times.

rric...@itspokernight.com

unread,
Feb 19, 2012, 12:31:23 PM2/19/12
to rhomobile
Well, I did find that just giving it a dummy function to stop the
timer accomplished my purpose...


def get_location
Rho::Timer.stop(url_for(:action => :stop_timer))
...
...
end

def stop_timer
# Do nothing here
end

Jon Tara

unread,
Feb 19, 2012, 1:17:34 PM2/19/12
to rhom...@googlegroups.com
In order to stop the timer, you have to give it the SAME URL that you gave when you first started the timer. It uses the URL to match-up which timer to start, since you can have multiple timers running at once.

Again, there is no need to "stop" a timer that has fired a callback. When it fires the callback, it has already stopped, and will NOT fire a second time. If you are seeing a callback fired more than once, it is because your application started the timer more than once.

You can stop ALL timers by calling Rho::Timer::stop with no parameter.

djeezus

unread,
Aug 27, 2014, 5:43:30 PM8/27/14
to rhom...@googlegroups.com
Hi,

it seems the stop_ALL is not working (any more) in rhodes-5.0.0 from git ?

Rho::Timer.stop / Rho::Timer::stop / Rho::Timer.stop() ... they all return :
APP| App error: wrong number of arguments (0 for 1)
...
I/APP     (16295): Error: wrong number of arguments (0 for 1)<br/>Trace: <br/>
I/APP     (16295): lib/rho/rho.rb:1195:in `stop'<br/>
...

I know I can use URL in Timer.stop, but in my implementation some functions can manually be triggered too, and based on the callback_data of the timer either a new Timer is started, or a webview refresh is done...
I'd like for all the timers to stop when an account switch occurs in my app.

grtz,
gert

Op zondag 19 februari 2012 19:17:34 UTC+1 schreef Jon Tara:
Reply all
Reply to author
Forward
0 new messages