lgierth / promise.rb

Promises/A+ for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Promise.fulfill and Promise.reject shorthands

sheerun opened this issue · comments

For now the readme says:

Promise.new
  .tap(&:fulfill)
  .then { Promise.new.tap(&:fulfill) }
  .then { Promise.new.tap(&:reject) }
  .then(nil, proc { |reason| p reason })

Last two PRs I've made introduced a change so following is possible:

Promise.new.fulfill
  .then { Promise.new.fulfill }
  .then { Promise.new.reject }
  .then(nil, proc { |reason| p reason })

What about an extra Promise.reject and Promise.fulfill, so following is possible?

Promise.fulfill
  .then { Promise.fulfill }
  .then { Promise.reject }
  .then(nil, proc { |reason| p reason })

Is it ok?

btw. it's also because I often return fulfilled promises like so: Promise.new.fulfill("value")

There is already a Promise.resolve method that works similar to your proposed Promise.fulfill. The naming is for consistency with javascript's Promise.resolve function

Javascript does have a Promise.reject function, so having one in this library would be appropriate.