Class: ZeevexConcurrency::Delay
- Includes:
- Observable, ZeevexConcurrency::Delayed::Bindable
- Defined in:
- lib/zeevex_concurrency/delay.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(computation = nil, options = {}, &block) ⇒ Delay
constructor
A new instance of Delay.
- #ready? ⇒ Boolean
- #wait(timeout = nil) ⇒ Object
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.
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, = {}, &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(.delete(:observer) || .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, = {}, &block) return callable if callable && callable.is_a?(ZeevexConcurrency::Delayed) new(callable, , &block) end |
Instance Method Details
#ready? ⇒ 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 |