5 ms·
You're making use of the deferred anti-pattern [0] on your own profile page [1]. [0] https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-de
by Kudos 11y ago
You're making use of the deferred anti-pattern [0] on your own profile page [1].
[0] https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern https://github.com/petkaantonov/bluebird/wiki/Promise-anti-p...
[1] https://pocketsquare.io/alanfriedman https://pocketsquare.io/alanfriedman
- bshimmin 11y agoTotally irrelevant to the topic at hand, but that first link really is grim reading - a complicated topic treated in a dismissive tone, chock-full of jargon, and probably leaving the average reader feeling slightly abused.
- Kudos 11y agoNot really, it demonstrates that displaying random snippets of code as some kind of portfolio is maybe not a great idea. I didn't think I needed to spell it out.
- bshimmin 11y agoI wasn't criticising you for sharing that link - just that the content of the link itself was, really, not the best (no doubt written with good intentions, though, I'm sure). I also think snippets of code are somewhat worthless, unless perhaps they're clever solutions to specific problems that really can be expressed in a dozen LoC. My GitHub gists, for example, are for the most part useless to anyone other than myself, and I wouldn't ever really think to share them as any kind of insight into my work.
- alanfriedman 11y agoBecause "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]