I read some questions about this topic here at stackoverflow but none of them seems to answer my doubts.
I know how to create async functions using process.nextTick:
var async_function = function(val, callback){
process.nextTick(function(){
callback(val);
});
};
I've also read about Promise, but how do you write async non-blocking functions without using libraries such as process, Promise, etc?
What's the native way? I thought first on this approach:
var async = function(val, cb) {
cb(val);
}
However, that function blocks:
async(3, function(val) {
console.log(val);
});
console.log(4);
// returns:
3
4
So what's the correct implementation? How could I write async functions without depending on those libraries?