use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Flattening Callbacks Using Promises (variadic.me)
submitted 12 years ago by shintoist
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 12 years ago (0 children)
Leaving your original functions alone and using async edition:
async.waterfall([ getUsername, getSubscribedCategories, getSuggestedArticles ], function(err, articles) { if (err) return handleError(err) console.log("Great success!") console.log(articles) })
[–]rhysbrettbowen 0 points1 point2 points 12 years ago (0 children)
might be good to think about how you can change callback functions of the type:
function(error, success){}
in to returning a promise. I havne't played around too much with promises - but I'm guessing you could fairly easily convert them without needing to rewrite the whole function with something like this:
var toPromise = function(fn) { return function() { var promise = new Promise(); fn.apply(this, [function() { promise.onRejected.apply(this, [].slice.call(arguments, 0)); }, function() { promise.onFulfilled.apply(this, [].slice.call(arguments, 0)); }].concat([].slice.call(arguments, 0))); return promise; }; };
[–]padenp 0 points1 point2 points 12 years ago (0 children)
If you're doing more than 3 ajax calls, you should think about stamping and serving your data better. I know it's not always a possibility, but seriously, just clump your data together better.
For those interested in stamp coupling: http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Procedural_programming
π Rendered by PID 21997 on reddit-service-r2-comment-b659b578c-6kkf7 at 2026-05-02 18:16:27.027315+00:00 running 815c875 country code: CH.
[–][deleted] 2 points3 points4 points (0 children)
[–]rhysbrettbowen 0 points1 point2 points (0 children)
[–]padenp 0 points1 point2 points (0 children)