Class: Chingu::AsyncTasks::Wait

Inherits:
Chingu::Async::BasicTask show all
Defined in:
lib/chingu/async_tasks/wait.rb

Overview

Halts processing of tasks until the passed-in block returns a true value, or the timeout expires. If no block is given, behaves as if the block returned nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout = nil, &condition) ⇒ Wait



35
36
37
38
39
40
# File 'lib/chingu/async_tasks/wait.rb', line 35

def initialize(timeout = nil, &condition)
  super()
  @result     = nil
  @age, @life = 0, timeout
  @condition  = condition
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition



32
33
34
# File 'lib/chingu/async_tasks/wait.rb', line 32

def condition
  @condition
end

#resultObject (readonly)

Returns the value of attribute result



33
34
35
# File 'lib/chingu/async_tasks/wait.rb', line 33

def result
  @result
end

#timeoutObject

Returns the value of attribute timeout



32
33
34
# File 'lib/chingu/async_tasks/wait.rb', line 32

def timeout
  @timeout
end

Instance Method Details

#finished?Boolean



47
48
49
# File 'lib/chingu/async_tasks/wait.rb', line 47

def finished?
  !!@result or (@life != nil and @age >= @life)
end

#update(object) ⇒ Object



42
43
44
45
# File 'lib/chingu/async_tasks/wait.rb', line 42

def update(object)
  @age += $window.milliseconds_since_last_tick
  @result = (@condition and @condition[])
end