The Collapse class is useful for deferring actions to a certain clock or scheduling them while reducing system load to a minimum. The Collapse takes a function to be deferred, a delta time span and a clock to defer to. An action is deferred by calling the defer method with arbitrary arguments. The function's value method is called with these arguments after the schedule delay. When defer is called before the function was executed, the function is deferred again by the schedule delay and the pending call is cancelled. The new arguments overwrite the previous (pending) arguments.
Creates a new Collapse.
func |
the function to execute when deferring; nil is allowed |
delta |
The amount of time to defer in seconds, defaults to 0.0. The first execution of the collapse will occur after |
clock |
The clock to execute the function within, defaults to AppClock |
Similiarly to defer, this sets the function args and schedules the collapse if it hadn't been started. Unlike defer, the scheduling delay is not reset.
... args |
zero or more arguments which are passed to the function upon execution |
Cancel future executions of the function.
Schedule execute the function with the arguments args
.
... args |
zero or more arguments which are passed to the function upon execution |
(Re)schedules the function for execution with the given list of arguments.
... args |
Zero or more arguments which are passed to the function upon execution. |
Resets the scheduling delay to the original delta. If the collapse was not yet scheduled, this method will do it. The cancel status is cleared.
(Re)schedules the function for execution with the arguments provided as an array.
args |
an array of zero or more arguments which are passed to the function upon execution. |
Similiarly to defer, this sets the function args and schedules the collapse if it hadn't been started. Unlike defer, the scheduling delay is not reset.
args |
an array of zero or more arguments which are passed to the function upon |
( ~collapseDelta = 0.5; // only update the value every 05 ~setValue = Collapse({ |val| ~collapsedValue.value = val; }, ~collapseDelta); View(bounds:300@300).front.layout_( VLayout( ~slider = Slider(bounds:300@40), ~nowValue = NumberBox(bounds:200@60).value_(0), ~collapsedValue = NumberBox(bounds:200@60).value_(0), nil ) ); ~slider.action = { |v| ~nowValue.value = v.value * 100; ~setValue.(v.value * 100); } )