Class: Obligation::Base

Inherits:
Object
  • Object
show all
Includes:
Obligation
Defined in:
lib/obligation/impl.rb

Direct Known Subclasses

Dependent, Value

Instance Method Summary collapse

Methods included from Obligation

create, on

Constructor Details

#initializeBase

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/obligation/impl.rb', line 8

def initialize
  @state  = :pending
  @mutex  = Mutex.new
  @event  = Concurrent::Event.new
  @reason = nil
end

Instance Method Details

#fulfilled?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/obligation/impl.rb', line 19

def fulfilled?
  state == :fulfilled
end

#pending?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/obligation/impl.rb', line 15

def pending?
  state == :pending
end

#reasonObject



31
32
33
# File 'lib/obligation/impl.rb', line 31

def reason
  @mutex.synchronize { @reason }
end

#rejected?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/obligation/impl.rb', line 23

def rejected?
  state == :rejected
end

#stateObject



27
28
29
# File 'lib/obligation/impl.rb', line 27

def state
  @mutex.synchronize { @state }
end

#thenObject



39
40
41
42
43
# File 'lib/obligation/impl.rb', line 39

def then
  return self unless block_given?

  Dependent.new(self, &Proc.new)
end

#value(timeout = 30) ⇒ Object



35
36
37
# File 'lib/obligation/impl.rb', line 35

def value(timeout = 30)
  _value(timeout)
end