-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
delay.reject() #7
Comments
Absolutely. I think this wouldn't be hard to add, and would be rather useful. However, I think that if we were to add this we should also do I'm happy to submit a PR if you want. |
Why? Do you need it for something? I kinda like how I can just write |
Completeness. It would be strange to have one and not the other. Plus, it's really trivial to write. |
But now you have two ways of doing the same thing, which I'm not a big fan of. I usually have one default export for the main use-case and then if there's any nice-to-haves, they're put as methods. Example: https://github.com/sindresorhus/log-update#logupdatetext- |
Why do think we shouldn't do it? Most will use |
In regard to the two-ways to do something: Sometimes its worth a little redundancy to avoid confusion down the road. Imagine that six months ago you wrote the following code: var delay = require('delay');
// ...
return delay.reject(1000, new Error('foo')); Without looking at the docs, you'd assume that you can use // FIXME: every once in a while, this resolves before the promise from #doSomethingElse, and causes problems.
return Promise.reject('foo'); You'd assume that you could just do this: // FIXME: every once in a while, this resolves before the promise from #doSomethingElse, and causes problems.
return delay.reject(10, 'foo'); |
Ok, how about we add it undocumented then? |
I am 👍 for the idea. Not sure where i stand on the string to error conversion. Seems a little magic. Also, this is primarily for testing - and if I am accepting user generated promises in my API, correctly handling non-error rejections is a something I want to test. |
Here's three reasons why I wouldn't do that:
|
👎 for resolve. Keep it simple. |
Ok. No |
What should we do if used like this: someprise.then(delay.reject(100));
someprise.then(delay.reject(100, new Error())); |
@jamestalmage Same as |
With You can then do: somePromise.then(delay(100), delay.reject(100)) To delay resolution and rejection |
Never mind. That makes sense. |
When I'm home in an hour or so I'll submit a PR |
👍 Good idea. |
Idea from: https://github.com/ariporad/ava/blob/c7b0154f8ae181e892d58ab1d50aee6154a9a743/test/test.js#L7-L12
If a string, it's converted to an
Error
, otherwise passed through.I know the first case is not like
Promise.reject()
, but is there any good reason not to reject with an error?@ariporad @jamestalmage Do you think it would be useful to have this here?
The text was updated successfully, but these errors were encountered: