Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise.fulfill and Promise.reject shorthands #28

Open
sheerun opened this issue Apr 29, 2017 · 2 comments
Open

Promise.fulfill and Promise.reject shorthands #28

sheerun opened this issue Apr 29, 2017 · 2 comments

Comments

@sheerun
Copy link
Contributor

sheerun commented Apr 29, 2017

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?

@sheerun
Copy link
Contributor Author

sheerun commented Apr 29, 2017

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

@dylanahsmith
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants