Class: ZeevexConcurrency::Promise
- Includes:
- Observable, Delayed::Bindable, Delayed::LatchBased
- Defined in:
- lib/zeevex_concurrency/promise.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(computation = nil, options = {}, &block) ⇒ Promise
constructor
A new instance of Promise.
Methods included from Delayed::LatchBased
Methods included from Delayed::Bindable
#bind, #binding, #bound?, #call, #execute
Methods inherited from Delayed
#exception, #exception?, #executed?, #set_result, #value, #wait
Constructor Details
#initialize(computation = nil, options = {}, &block) ⇒ Promise
Returns a new instance of Promise.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zeevex_concurrency/promise.rb', line 10 def initialize(computation = nil, = {}, &block) @mutex = Mutex.new @exec_mutex = Mutex.new @exception = nil @done = false @result = false @executed = false _initialize_latch # has to happen after exec_mutex initialized bind(computation, &block) if (computation || block) Array(.delete(:observer) || .delete(:observers)).each do |observer| self.add_observer observer end end |
Class Method Details
.create(callable = nil, options = {}, &block) ⇒ Object
28 29 30 31 |
# File 'lib/zeevex_concurrency/promise.rb', line 28 def self.create(callable = nil, = {}, &block) return callable if callable && callable.is_a?(ZeevexConcurrency::Delayed) new(callable, , &block) end |