Method: Concurrent::Promise.fulfill

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

.fulfill(value, opts = {}) ⇒ Promise

Create a new ‘Promise` and fulfill it immediately.

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

Returns:

  • (Promise)

    the newly created ‘Promise`

Raises:

  • (ArgumentError)

    if no block is given



224
225
226
# File 'lib/concurrent-ruby/concurrent/promise.rb', line 224

def self.fulfill(value, opts = {})
  Promise.new(opts).tap { |p| p.send(:synchronized_set_state!, true, value, nil) }
end