-
Notifications
You must be signed in to change notification settings - Fork 4
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
discovery of resolver #5
Comments
This is a pretty interesting idea. A bit weird, but not bad. If we went with a promise-constructor approach, though, it would be more natural, via the function timeout(promise, time) {
var Promise = promise.constructor;
return new Promise(function (resolve, reject) {
promise.then(resolve, reject);
setTimeout(function () {
reject(new Error('Operation timed out.'));
}, time);
});
} Writing this down actually gives me the strongest argument for the constructor pattern over the deferred pattern. |
This seems like a great way to achieve all of the desired features: new Promise(function (resolve, reject) {
resolve(promise);
setTimeout(function () {
reject(new Error('Operation timed out.'));
// reject function has its own "extension" properties
// so you could also do this (feel free to bikeshed these names):
// resolve.createRejectedPromise(new Error('Operation timed out.'));
// or this:
// resolve.createCancellablePromise(promise);
// or this:
// resolve.createSomeObservablePromise(promise);
}, 100);
}); Pros:
Cons:
|
I like this hybrid. It makes the most common operations, resolve & reject, totally obvious and easy to use, while still allowing the |
@unscriptable @briancavalier both those comments are nothing to do with this issue and everything to do with #7. This issue is about discovering what promise library was used to create an existing promise (so as to be able to create a new promise from the same library). You're comments are about what arguments should be passed to the resolver function. |
I worry about the memory footprint of having
And we don't have |
@juandopazo I don't see how your comments relate to this issue, I assume you are still talking about #7. |
Yup, my bad. |
Consider a utility function, timeout:
The problem with utility functions like these is that I'm not going to get out the same type of promise that I put in. If I passed in something like a Q promise and get back something like a promises-a I loose a lot of functionality.
What if promises came with a property that tells you how to make a new promise, resolver pair:
That way if I passed a Q promise in, I'd get a Q promise out.
Do people want this method? What should it be called?
The text was updated successfully, but these errors were encountered: