Sha256: e10a3310701e6245030098450ae65d213288fa88c1ac54d6ab7f2d327adfd46a

Contents?: true

Size: 813 Bytes

Versions: 6

Compression:

Stored size: 813 Bytes

Contents

require 'thread'
require 'timeout'

require 'concurrent/dereferenceable'
require 'concurrent/event'

module Concurrent

  module Obligation
    include Dereferenceable

    attr_reader :state
    attr_reader :reason

    # Has the obligation been fulfilled?
    # @return [Boolean]
    def fulfilled?() return(@state == :fulfilled); end
    alias_method :realized?, :fulfilled?

    # Has the obligation been rejected?
    # @return [Boolean]
    def rejected?() return(@state == :rejected); end

    # Is obligation completion still pending?
    # @return [Boolean]
    def pending?() return(@state == :pending); end

    def value(timeout = nil)
      event.wait(timeout) unless timeout == 0 || @state != :pending
      super()
    end

    protected

    def event
      @event ||= Event.new
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
concurrent-ruby-0.4.1 lib/concurrent/obligation.rb
concurrent-ruby-0.4.0 lib/concurrent/obligation.rb
concurrent-ruby-0.3.2 lib/concurrent/obligation.rb
concurrent-ruby-0.3.1 lib/concurrent/obligation.rb
concurrent-ruby-0.3.1.pre.2 lib/concurrent/obligation.rb
concurrent-ruby-0.3.1.pre.1 lib/concurrent/obligation.rb