2014. augusztus 5., kedd

ELI5 Sync/Async (blocking/non-blocking) in a Node or general context


Hi everyone,


I was wondering if anyone could help with explaining me simply what asynchronous and synchronous really means. I have been learning Node for the last couple of days, I have used ajax calls in JQuery before, and I guess i soooort of understand what async is (i used it to submit form without a submit button). But a good explanation would help me a lot I think. Also in the context of Node, how does this all relate to callbacks. I can see the pattern of how people are using it, I can write it, but to be fair I don't really understand why I do it or why this is good for me. for example:



var files = buffer = fs.readFileSync(process.argv[2]); var lines = buffer.toString().split('\n');

vs.



fs.readFile(process.argv[2], 'utf8', function(err, data){ var lines = data.split('\n').length - 1; console.log(lines) });

Any help would be really appreciated guys, sorry that I am always posting noob questions. Thanks






Nincsenek megjegyzések:

Megjegyzés küldése