Class: TT::DeferredEvent
- Inherits:
-
Object
- Object
- TT::DeferredEvent
- Defined in:
- TT_Lib2/deferred_event.rb
Overview
Special Proc like object that limits the frequency it's executed.
Designed to be used with change
events for TT::GUI::Textbox.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#call(value) ⇒ Boolean
True is the event was executed.
-
#initialize(delay = 0.2, &block) ⇒ DeferredEvent
constructor
A new instance of DeferredEvent.
Constructor Details
#initialize(delay = 0.2, &block) ⇒ DeferredEvent
Returns a new instance of DeferredEvent
22 23 24 25 26 27 28 |
# File 'TT_Lib2/deferred_event.rb', line 22 def initialize( delay = 0.2, &block ) @proc = block @delay = delay @last_value = nil @timer = nil @suppress_event_if_value_not_changed = true end |
Instance Attribute Details
#suppress_event_if_value_not_changed ⇒ Object
16 17 18 |
# File 'TT_Lib2/deferred_event.rb', line 16 def suppress_event_if_value_not_changed @suppress_event_if_value_not_changed end |
Instance Method Details
#call(value) ⇒ Boolean
Returns True is the event was executed.
34 35 36 37 38 39 40 41 42 |
# File 'TT_Lib2/deferred_event.rb', line 34 def call( value ) return false if @suppress_event_if_value_not_changed && value == @last_value UI.stop_timer( @timer ) if @timer @timer = UI.start_timer( @delay, false ) { UI.stop_timer( @timer ) # Ensure it only runs once. @proc.call( value ) } true end |