Class: Garcon::Future
- Includes:
- ExecutorOptions
- Defined in:
- lib/garcon/task/future.rb
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
#complete?, #exception, #fulfilled?, #incomplete?, #pending?, #reason, #rejected?, #state, #unscheduled?, #value, #value!, #wait, #wait!
Methods included from Dereferenceable
Constructor Details
#initialize(opts = {}) { ... } ⇒ Future
Create a new ‘Future` in the `:unscheduled` state.
42 43 44 45 46 47 48 49 |
# File 'lib/garcon/task/future.rb', line 42 def initialize(opts = {}, &block) raise ArgumentError.new('no block given') unless block_given? super(IVar::NO_VALUE, opts) @state = :unscheduled @task = block @executor = get_executor_from(opts) || Garcon.global_io_executor @args = get_arguments_from(opts) end |
Class Method Details
.execute(opts = {}) { ... } ⇒ Future
Create a new ‘Future` object with the given block, execute it, and return the `:pending` object.
93 94 95 |
# File 'lib/garcon/task/future.rb', line 93 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`.
67 68 69 70 71 72 |
# File 'lib/garcon/task/future.rb', line 67 def execute if compare_and_set_state(:pending, :unscheduled) @executor.post(@args){ work } self end end |