Class: ZeevexConcurrency::Delay

Inherits:
Delayed
  • Object
show all
Includes:
Observable, ZeevexConcurrency::Delayed::Bindable
Defined in:
lib/zeevex_concurrency/delay.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ZeevexConcurrency::Delayed::Bindable

#bind, #binding, #bound?, #call, #execute

Methods inherited from Delayed

#exception, #exception?, #executed?, #set_result, #value

Constructor Details

#initialize(computation = nil, options = {}, &block) ⇒ Delay

Returns a new instance of Delay.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zeevex_concurrency/delay.rb', line 9

def initialize(computation = nil, options = {}, &block)
  raise ArgumentError, "Must provide computation or block for a future" unless (computation || block)

  @mutex       = Mutex.new
  @exec_mutex  = Mutex.new
  @exception   = nil
  @done        = false
  @result      = false
  @executed    = false

  # has to happen after exec_mutex initialized
  bind(computation, &block)

  Array(options.delete(:observer) || options.delete(:observers)).each do |observer|
    add_observer observer
  end
end

Class Method Details

.create(callable = nil, options = {}, &block) ⇒ Object



27
28
29
30
# File 'lib/zeevex_concurrency/delay.rb', line 27

def self.create(callable = nil, options = {}, &block)
  return callable if callable && callable.is_a?(ZeevexConcurrency::Delayed)
  new(callable, options, &block)
end

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/zeevex_concurrency/delay.rb', line 36

def ready?
  true
end

#wait(timeout = nil) ⇒ Object



32
33
34
# File 'lib/zeevex_concurrency/delay.rb', line 32

def wait(timeout = nil)
  true
end