Class: Concurrent::Future
Overview
Class Method Summary collapse
-
.execute(opts = {}) { ... } ⇒ Future
Create a new ‘Future` object with the given block, execute it, and return the `:pending` object.
Instance Method Summary collapse
-
#execute ⇒ Future
Execute an ‘:unscheduled` `Future`.
-
#initialize(opts = {}) { ... } ⇒ Future
constructor
Create a new ‘Future` in the `:unscheduled` state.
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.
34 35 36 37 38 39 40 41 |
# File 'lib/concurrent/future.rb', line 34 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 @args = OptionsParser::get_arguments_from(opts) end |
Class Method Details
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`.
58 59 60 61 62 63 |
# File 'lib/concurrent/future.rb', line 58 def execute if compare_and_set_state(:pending, :unscheduled) @executor.post(@args){ work } self end end |