Class: ZeevexConcurrency::Future
- Includes:
- Observable, Delayed::Bindable, Delayed::Cancellable, Delayed::LatchBased
- Defined in:
- lib/zeevex_concurrency/future.rb
Constant Summary collapse
- @@worker_pool =
@@worker_pool = ZeevexConcurrency::EventLoop.new
ZeevexConcurrency::ThreadPool::FixedPool.new
Class Method Summary collapse
- .create(callable = nil, options = {}, &block) ⇒ Object (also: future)
- .shutdown ⇒ Object
- .worker_pool ⇒ Object
- .worker_pool=(pool) ⇒ Object
Instance Method Summary collapse
-
#initialize(computation = nil, options = {}, &block) ⇒ Future
constructor
A new instance of Future.
Methods included from Delayed::Cancellable
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) ⇒ Future
Returns a new instance of Future.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/zeevex_concurrency/future.rb', line 17 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 _initialize_latch # has to happen after exec_mutex initialized bind(computation, &block) if (computation || block) Array(.delete(:observer) || .delete(:observers)).each do |observer| add_observer observer end end |
Class Method Details
.create(callable = nil, options = {}, &block) ⇒ Object Also known as: future
41 42 43 44 45 46 |
# File 'lib/zeevex_concurrency/future.rb', line 41 def self.create(callable=nil, = {}, &block) nfuture = ZeevexConcurrency::Future.new(callable, , &block) (.delete(:event_loop) || worker_pool).enqueue nfuture nfuture end |
.shutdown ⇒ Object
37 38 39 |
# File 'lib/zeevex_concurrency/future.rb', line 37 def self.shutdown self.worker_pool.stop end |
.worker_pool ⇒ Object
48 49 50 |
# File 'lib/zeevex_concurrency/future.rb', line 48 def self.worker_pool @@worker_pool end |
.worker_pool=(pool) ⇒ Object
52 53 54 |
# File 'lib/zeevex_concurrency/future.rb', line 52 def self.worker_pool=(pool) @@worker_pool = pool end |