Sha256: 5f80712ec573a4bd7a20137326b45961f32734c1becae91ff08c28bbb1ec481d

Contents?: true

Size: 561 Bytes

Versions: 2

Compression:

Stored size: 561 Bytes

Contents

module Dharma
  class KeptPromise
    include Dharma::PromiseActions

    def initialize(value, as)
      @value, @as = value, as
    end

    def failure?
      @as == :failure
    end

    def result(at_most = nil)
      if @as == :failure
        raise @value
      else
        return @value
      end
    end

    def ready(at_most = nil)
      return self
    end

    def value
      @value
    end

    def completed?
      true
    end

    def on_complete(cb = nil, &block)
      cb ||= block

      cb.call(@value, @as)
      return
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dharma-0.9.1 lib/dharma/kept_promise.rb
dharma-0.9.0 lib/dharma/kept_promise.rb