module MrDarcy::Promise::State

Implementation of the State Pattern for Promises.

Public Instance Methods

state(stateful) click to toggle source

Return an instance of the correct State class based on the state of the passed in object.

# File lib/mr_darcy/promise/state.rb, line 14
def state stateful
  case stateful.send :state
  when :unresolved
    Unresolved.new stateful
  when :resolved
    Resolved.new stateful
  when :rejected
    Rejected.new stateful
  else
    raise "Unknown state #{stateful.state}"
  end
end