-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support promise arguments to proxy methods #152
Comments
I have been thinking about it for other reasons. We'll track the issue |
Alternatively, can you think of any better solutions for the underlying problem? For example, getEmail(...)
.then(function(email) {
return Q.deepResolve({
email: email,
user: getUserInfo(email) //promise
});
}); Maybe I'll add a |
I think |
Should it go in Q itself or in Qx? |
Or in QQ? :P Up to @kriskowal though. |
It looks like QQ already has it. |
Yeah, but QQ is "out of service." Qx may be a good successor/replacement... |
I just realized that there is a much simpler solution to the original problem: getEmail(...)
.then(function(email) {
return Q.all([ email, getUserInfo(email) ]);
}).spread(function(email, user) {
...
}); |
I use that pattern all the time, and it serves me well. To make it equivallent to the original example you need to do: getEmail(...)
.then(function(email) {
return Q.all([ email, getUserInfo(email) ]);
}).spread(function(email, user) {
return {email: email, user: user};
}); which I assumed you felt was too clunky. It can be a little clunky and a deep-resolve would probably be useful in more complex scenarios. |
@kriskowal, @SLaks Are we happy with the solutions proposed here? Namely, slight-hackery with |
I would close this issue and open some new ones:
|
Thanks @SLaks! |
I personally like
Also it's very likely to have some utility functions in toolbox already that can
where record is: function record() {
var names = Array.prototype.slice.call(arguments)
return function() {
var values = arguments
return reduce.names(function(result, name, index) {
result[name] = values[index]
return result
}, {})
}
} |
Another interesting consequence of describing computations via |
Background
I frequently need to write code that takes a value from one promise, and puts it into an object alongside a value from another promise.
For example:
This obviously won't work, because it won't wait for the inner promise to finish.
I'd like to be able to do this without nesting callbacks.
Feature request
The closest option I can find within Q is the
.put()
method:However, this doesn't work, because
.put()
doesn't resolve promises in its arguments.The closest working code I can come up with is
Can you change all of the proxy methods to resolve any promises in their argument lists?
The text was updated successfully, but these errors were encountered: