40 ms·
Because "request" returns a promise? I created the deferred object because I'm waiting on multiple async operations (get gravatar url, download gravatar locally
by alanfriedman 11y ago
Because "request" returns a promise? I created the deferred object because I'm waiting on multiple async operations (get gravatar url, download gravatar locally and upload to s3). Or am I missing something?
- WorldMaker 11y agoThe trick is learning how to compose promises out of one another. For instance, then() on a promise doesn't just support a callback, but another promise or a function that returns another promise. Often you can build multiple async operations as chains and flows of promises. Additionally there are "higher level" compositions of promises such as Q.whenAll(promise1, promise2, ...).then(), making it easier to deal with things like parallel promises. Also, it's often cleaner to use something like Q.nfcall to turn a callback accepting function (like request in your example) itself into a promise that can be chained. (I just noticed that this is contrary to Q's own documentation which surprisingly is pro-deferred.)
- deleted 11y ago[deleted]