javascript - how to understand callbacks and async.parallel in node -
I am very new to javascript and callback, so my apologies if it's a stupid question, Code that came with the execution of the required method based on the docs:
async = require ('async') async.parallel ([function (callback) {setTimeout (function () (Callback (tap, 'one');}, 800);}, function (callback) {setTimeout (function () {callback (tap, 'two');}, 100);}], function (error, result } {console.log (the result)}) call it node f Moving with the oo.js the result array prints [code] ['one', 'two'] as the docs states that it will happen that what I do not understand is that it How it works: When you pass callback as a parameter for each function and then callback to callback (null, res) , What is it really being said? I did not really define any function callback, nor did I have any kind of Preting is passed as the callback function parameters, but everything magically works fine I'm completely missing the point here? Or is it really async ?
Is Under-Hood Magic? You have not a callback in the functions function, the async module is . This is a special task that the module passes through your work, when the call is made, checks if there is any other work left. Here's something that is being done inside async : function myParallel (function, finalcb) {var workspace = function. Length, result = [], neglect = false; Function callback (mistake, result) {if (ignored) return; If (mistake) {ignore = true; Last cc & amp; finalcb (mistake); } And if (- Task Lift === 0) {ignore = true; Last cc & amp; Final cb (empty, result); } And results.push (results); } Tasks.forEach (taskfn) {taskfn (callback);}); } MyParallel {[function (callback) {callback (null, 'one');}, 800);}, function (callback) {setTimeout (function () {callback (null, 'two') ;}, 100);}], function (fault, result) {console.log (result)});
Comments
Post a Comment