Method: Concurrent::Promise#initialize

Defined in:
lib/concurrent-ruby/concurrent/promise.rb

#initialize(opts = {}) { ... } ⇒ Promise

Initialize a new Promise with the provided options.

Parameters:

  • opts (Hash) (defaults to: {})

    the options used to define the behavior at update and deref and to specify the executor on which to perform actions

Options Hash (opts):

  • :executor (Executor)

    when set use the given Executor instance. Three special values are also supported: :io returns the global pool for long, blocking (IO) tasks, :fast returns the global pool for short, fast operations, and :immediate returns the global ImmediateExecutor object.

  • :dup_on_deref (Boolean) — default: false

    Call #dup before returning the data from Concern::Obligation#value

  • :freeze_on_deref (Boolean) — default: false

    Call #freeze before returning the data from Concern::Obligation#value

  • :copy_on_deref (Proc) — default: nil

    When calling the Concern::Obligation#value method, call the given proc passing the internal value as the sole argument then return the new value returned from the proc.

  • :parent (Promise)

    the parent Promise when building a chain/tree

  • :on_fulfill (Proc)

    fulfillment handler

  • :on_reject (Proc)

    rejection handler

  • :args (object, Array)

    zero or more arguments to be passed the task block on execution

Yields:

  • The block operation to be performed asynchronously.

Raises:

  • (ArgumentError)

    if no block is given

See Also:



210
211
212
213
# File 'lib/concurrent-ruby/concurrent/promise.rb', line 210

def initialize(opts = {}, &block)
  opts.delete_if { |k, v| v.nil? }
  super(NULL, opts.merge(__promise_body_from_block__: block), &nil)
end