So I recently started playing around with Node.js which showed me asynchronous code in a way I had seen it before. The problem that I face however is that node node executes almost functions call asynchronously (if I understand correctly). So I have two functions A, B
who preform some database actions. Function A
needs to complete before B can start. However I realized that just calling A
after B
clearly doesn't cut it. So I think the node thing to do would be to have a callback :). But my productions app will probably have series with A to Z so that could get messy. However I would really appreciate an example of how to implement such an callback in node.js.
var http = require('http');
function runAllFunc() {
funcA();
funcB();
};
var server = http.createServer(function(req,res) {
syncFunc();
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('dde');
}).listen(8080);