This is a pretty common pattern for any work you have to do asynchronously, pretty much all libraries should be implementing this for you so the first 3 lines should be all you code
getSomething("id", function(thething) {
// one true code path
});
function getSomething(id, callback) {
var myThing = synchronousCache.get("id:3244");
if(myThing) {
callback(null, myThing);
} else {
async(id, callback);
}
}
a minor quibble with language style isnt exactly what I would call "A Giant Step Backwards"
Amen to that. The power of Node is this language style already makes tons of sense to experienced front-end developers who deal with async flow for everything they do.
I was under the impression that you could not do _anything_ synchronous? What if the call blocks for 100ms? or 1000ms? Won't that delay all other clients and all other requests?
It's kind of a dick move to make a inflammatory, flamebait blog post and then later admit you didn't actually know what you were talking about. Maybe you should have actually understood the technology you were working with before making knee-jerk snap judgements.
It's not an inflammatory blog post. The headline might be a little annoying to some, but not to most of us. There are negative headlines about every programming language platform.
Also it's a reminder for Node.js developers to make good use of async patterns, lest their code look silly. Besides async, which Fenn mentions in the comments, there's EventEmitters and Backbone.js for doing different styles of async programming. And there are a few other libraries that are a lot like https://github.com/caolan/async .
Sure, everyone has to start somewhere, and to be perfectly honest, I ran into many of the same issues.
The difference is in what happened afterward. What I did then was to try to understand why Node.js did things differently and how I could accomplish my goals in an idiomatic way. I didn't try to shoe-horn in my existing mental framework for how things should work, and then throw my hands in the air when they didn't.
However, what I didn't do was immediately run to Alert the Internets about what "A Giant Step Backward" Node.js is.