From: "S P Arif Sahari Wibowo" <
[email protected]>
Subject: Re: Ruby Tk: how to make something happen periodically?
Date: Sun, 18 Feb 2007 08:20:11 +0900
Message-ID: said:
That said, do you know about proc in the arguments for TkTimer's start
method / parameter, where its result goes?
Please try this.
--------------------------------------------------------------
TkTimer.new(100, 2, proc{|tm|
p [:body, tm.class, tm.current_args, tm.return_value]
tm.return_value + 1
}).start(500, proc{|tm|
p [:init, tm.class, tm.current_args, tm.return_value]
4
},
1,2,3)
--------------------------------------------------------------
It will returns
--------------------------------------------------------------
(wait 500ms)
[:init, TkTimer, [1, 2, 3], nil]
(wait 100ms)
[:body, TkTimer, [], 4]
(wait 100ms)
[:body, TkTimer, [], 5]
--------------------------------------------------------------
A TkTimer object keeps the result (last value) of the previous proc.
You can get the result by TkTimer#return_value method.
BTW, TkTimer class is not accurate. Because, the interval shows
the wait between finish of previous proc and start of next proc.
So, the timer delays by the time cost of the proc.
TkRTTimer class is a little more accurate than TkTimer class.
It modifies the interval based on the difference between the requested
time and current time. It doesn't mean to keep same intervals.
But it will make the delay by repeating minimum.
Please try "ext/tk/sample/tkrttimer.rb".
It will show you a part of properties of TkRTTimer class.