Sha256: 4b829743d1e8c5ca81892d5c15d8a03100554b3f666293ae7775e2471bac0dac

Contents?: true

Size: 489 Bytes

Versions: 2

Compression:

Stored size: 489 Bytes

Contents

module Whenner
  module Conversions
    module_function

    # Convert any object to a promise. When the object in question responds to
    # `to_promise`, the result of that method will be returned. If not, a new
    # deferred object is created and immediately fulfilled with the given
    # object.
    #
    # @param [Object] obj
    # @return [Promise]
    def Promise(obj)
      return obj.to_promise if obj.respond_to?(:to_promise)
      Deferred.new.fulfill(obj)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whenner-0.2.0 lib/whenner/conversions.rb
whenner-0.1.1 lib/whenner/conversions.rb