Please, just to clear something up in my head...
I am used to writing using asynchronous functions in libraries, but how do I write my own?
To illustrate my question I have made up a module called 'MadMathz'
I am aware that the following is an example usage of an asynchronous function :
//load module
var mM = require('./MadMathz');
//perform a function
mM.async_function_addthree(12, function(result) {
console.log(result)
});
//do something straight afterwards
console.log('Logging this straight after instead of waiting for computation');
I'm aware that the second argument to the function is the callback, but how is a function such as 'async_function_addthree' defined? Let's say for the purpose of this example that async_function_addthree just adds 3 to the first argument.
I just confused myself so much trying to write what I thought it might be. Am I totally on the wrong track? I feel like I am close to getting there with node.js but this needs clearing up.
Please explain rather than linking me somewhere if possible. I'm sure others will benefit from this question.