Class: Concurrent::Future
Overview
Class Method Summary collapse
-
.execute(opts = {}) { ... } ⇒ Future
Create a new
Futureobject with the given block, execute it, and return the:pendingobject.
Instance Method Summary collapse
-
#execute ⇒ Future
Execute an
:unscheduledFuture. -
#initialize(opts = {}) { ... } ⇒ Future
constructor
Create a new
Futurein the:unscheduledstate.
Methods inherited from IVar
Methods included from Observable
#add_observer, #count_observers, #delete_observer, #delete_observers, #with_observer
Methods included from Obligation
#completed?, #exception, #fulfilled?, #incomplete?, #no_error!, #pending?, #reason, #rejected?, #state, #unscheduled?, #value, #value!, #wait
Methods included from Dereferenceable
Constructor Details
#initialize(opts = {}) { ... } ⇒ Future
Create a new Future in the :unscheduled state.
32 33 34 35 36 37 38 |
# File 'lib/concurrent/future.rb', line 32 def initialize(opts = {}, &block) raise ArgumentError.new('no block given') unless block_given? super(IVar::NO_VALUE, opts) @state = :unscheduled @task = block @executor = OptionsParser::get_executor_from(opts) || Concurrent.configuration.global_operation_pool end |
Class Method Details
.execute(opts = {}) { ... } ⇒ Future
Create a new Future object with the given block, execute it, and return the :pending object.
89 90 91 |
# File 'lib/concurrent/future.rb', line 89 def self.execute(opts = {}, &block) Future.new(opts, &block).execute end |
Instance Method Details
#execute ⇒ Future
Execute an :unscheduled Future. Immediately sets the state to :pending and passes the block to a new thread/thread pool for eventual execution. Does nothing if the Future is in any state other than :unscheduled.
57 58 59 60 61 62 |
# File 'lib/concurrent/future.rb', line 57 def execute if compare_and_set_state(:pending, :unscheduled) @executor.post{ work } self end end |