Class: Livecode::Delay

Inherits:
Object
  • Object
show all
Defined in:
lib/livecode/delay.rb

Overview

Delay

Delay lets you schedule a block for later.

Delay.new(1000){puts "One second later"}
later = proc{puts "I am a proc"}
Delay.new(500, later)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, proc = nil, &block) ⇒ Delay

Time is specified in milliseconds



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/livecode/delay.rb', line 15

def initialize(time, proc=nil, &block)
  @time = time || 1
  if proc
    @proc = proc
  elsif block_given?
    @proc = block
  end
  Silenceable.apply(@proc) if @proc
  if @proc && !@proc.silenced?
    @thread = Thread.new do
      sleep @time.to_f / 1000
      @proc.call
    end
  end
end

Instance Attribute Details

#procObject

Returns the value of attribute proc.



12
13
14
# File 'lib/livecode/delay.rb', line 12

def proc
  @proc
end

#timeObject

Returns the value of attribute time.



12
13
14
# File 'lib/livecode/delay.rb', line 12

def time
  @time
end