Thursday, 15 September 2011

javascript - how to think about asynchronous callback operations in Node.js -



javascript - how to think about asynchronous callback operations in Node.js -

learnyounode commandline based learn-by-doing-and-getting-your-results-tested tutorial javascript's node

in 7th tutorial, thought create of http client using node.js's http's function.

the function has 2 arguments

the url a callback function asynchronous job

so scourgd surface of net looking way continously take info till operation ended. after while seeing every reply pretty much along lines of

function callback(res){ res.on("data",function (data) { console.log(data.tostring());}) } http.get(url,callback)

i thought maybe failing inbuilt tests give me clue see how create multiple calls weirdly plenty passed multiple calls test.so thought test called file , hence function, multiple times .. after tries..i realised wasn't case.

so question : goes on behind async phone call ? how possible mechanism phone call more once? other surprises should expect ? me taking black box thinking whole new level , place on par thinking list monads atm.

i think key point understand res eventemitter (incomingmessage more accurate), function named callback (only 1 time on response event of httpclientrequest object create when calling http.get()) attach event listener data event of res. without going details, optimise info flow, when receive info bytes network buffer filled , when total event 'data' triggered can process incoming chunk. hence callback have set data event executed on every chunk of info coming network

javascript node.js

No comments:

Post a Comment