Class: IOPromise::Base

Inherits:
Promise
  • Object
show all
Defined in:
lib/iopromise.rb

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



16
17
18
19
20
21
22
# File 'lib/iopromise.rb', line 16

def initialize(*)
  @instrument_begin = []
  @instrument_end = []
  @started_executing = false
  
  super
end

Instance Method Details

#beginningObject



30
31
32
33
# File 'lib/iopromise.rb', line 30

def beginning
  @instrument_begin.each { |cb| cb.call(self) }
  @started_executing = true
end

#fulfill(value) ⇒ Object



44
45
46
47
# File 'lib/iopromise.rb', line 44

def fulfill(value)
  notify_completion(value: value)
  super(value)
end

#instrument(begin_cb = nil, end_cb = nil) ⇒ Object

Raises:



24
25
26
27
28
# File 'lib/iopromise.rb', line 24

def instrument(begin_cb = nil, end_cb = nil)
  raise ::IOPromise::Error.new("Instrumentation called after promise already started executing") if @started_executing
  @instrument_begin << begin_cb unless begin_cb.nil?
  @instrument_end << end_cb unless end_cb.nil?
end

#notify_completion(value: nil, reason: nil) ⇒ Object



39
40
41
42
# File 'lib/iopromise.rb', line 39

def notify_completion(value: nil, reason: nil)
  @instrument_end.each { |cb| cb.call(self, value: value, reason: reason) }
  @instrument_end = []
end

#reject(reason) ⇒ Object



49
50
51
52
# File 'lib/iopromise.rb', line 49

def reject(reason)
  notify_completion(reason: reason)
  super(reason)
end

#started_executing?Boolean

Returns:

  • (Boolean)


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

def started_executing?
  @started_executing
end