class IOPromise::Base

Public Instance Methods

beginning() click to toggle source
# File lib/iopromise.rb, line 30
def beginning
  @instrument_begin&.each { |cb| cb.call(self) }
  @instrument_begin&.clear
  @started_executing = true
end
cancel() click to toggle source

makes this promise inert, ensuring that promise chains do not continue propegation once this promise has been cancelled.

# File lib/iopromise.rb, line 70
def cancel
  return unless pending?
  
  @cancelled = true
  @observers = []

  execute_pool.promise_cancelled(self)
end
cancelled?() click to toggle source
# File lib/iopromise.rb, line 79
def cancelled?
  !!defined?(@cancelled)
end
execute_pool() click to toggle source

Subclasses are expected to implement 'execute_pool' to return an IOPromise::ExecutorPool that is responsible for completing the given promise.

# File lib/iopromise.rb, line 64
def execute_pool
  raise NotImplementedError
end
fulfill(value) click to toggle source
Calls superclass method
# File lib/iopromise.rb, line 45
def fulfill(value)
  return if cancelled?
  notify_completion(value: value)
  super(value)
end
instrument(begin_cb = nil, end_cb = nil) click to toggle source
# File lib/iopromise.rb, line 18
def instrument(begin_cb = nil, end_cb = nil)
  raise ::IOPromise::Error.new("Instrumentation called after promise already started executing") if started_executing?
  unless begin_cb.nil?
    @instrument_begin ||= []
    @instrument_begin << begin_cb
  end
  unless end_cb.nil?
    @instrument_end ||= []
    @instrument_end << end_cb
  end
end
notify_completion(value: nil, reason: nil) click to toggle source
# File lib/iopromise.rb, line 40
def notify_completion(value: nil, reason: nil)
  @instrument_end&.each { |cb| cb.call(self, value: value, reason: reason) }
  @instrument_end&.clear
end
reject(reason) click to toggle source
Calls superclass method
# File lib/iopromise.rb, line 51
def reject(reason)
  return if cancelled?
  notify_completion(reason: reason)
  super(reason)
end
started_executing?() click to toggle source
# File lib/iopromise.rb, line 36
def started_executing?
  !!@started_executing
end
wait() click to toggle source
Calls superclass method
# File lib/iopromise.rb, line 57
def wait
  raise IOPromise::CancelledError if cancelled?
  super
end