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.
188 189 190 191 192 193 |
# File 'lib/vimamsa/util.rb', line 188 def initialize(wait_time, _proc) @wait_time = wait_time @proc = _proc @lastt = Time.now @thread_running = false end |
Instance Method Details
#run ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/vimamsa/util.rb', line 208 def run() @lastt = Time.now if @thread_running == false @thread_running = true start_thread end end |
#start_thread ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/vimamsa/util.rb', line 195 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 |