Class: DelayExecutioner
- Inherits:
-
Object
- Object
- DelayExecutioner
- Defined in:
- lib/vimamsa/util.rb
Overview
Execute proc after wait_time seconds after last .run call. Used for image scaling after window resize
Instance Method Summary collapse
-
#initialize(wait_time, _proc) ⇒ DelayExecutioner
constructor
A new instance of DelayExecutioner.
- #run ⇒ Object
- #start_thread ⇒ Object
Constructor Details
#initialize(wait_time, _proc) ⇒ DelayExecutioner
Returns a new instance of DelayExecutioner.
110 111 112 113 114 115 |
# File 'lib/vimamsa/util.rb', line 110 def initialize(wait_time, _proc) @wait_time = wait_time @proc = _proc @lastt = Time.now @thread_running = false end |
Instance Method Details
#run ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/vimamsa/util.rb', line 130 def run() @lastt = Time.now if @thread_running == false @thread_running = true start_thread end end |
#start_thread ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vimamsa/util.rb', line 117 def start_thread Thread.new { while true sleep 0.1 if Time.now - @lastt > @wait_time @proc.call @thread_running = false break end end } end |