I have a situation where I create a node module that returns only after the asynchronous operation is completed. One way to do this (shown below) is to assign module.exports a function with a callback parameter. Inside the function, you will then return the callback.
Here is an example of what I am describing with a completed callback:
module.exports = function(done) {
process.nextTick(function() {
done();
}
}
Where I hung up is how the callback is made, given that I don't define it anywhere ...
For example, in javascript in vanilla, I can pass it as a parameter and then call it inside the function while I create the callback function in the call.
function testAsyncCb(msg, done) {
console.log(msg);
setTimeout( function() {
done();
}, 1000);
console.log("last line in code");
}
testAsyncCb("testing", function(){ console.log("done"); });
Back in the first node example, somewhere calling module.exports using require () creates a function for done () to get the solution right? If not, how is callback resolved?
, . / .