what is res.on() in http request? #272
Replies: 3 comments
-
Posted at 2014-05-20 by @gfwilliams Thanks... I'll try and update the docs. Basically:
The HTTP image loader example does this:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-20 by DrAzzy Cool, thanks, just what I was looking for. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-20 by @gfwilliams I've just updated the http docs, and I just tweaked the example above: If you define bmpString in the callback function (rather than outside) then you won't have any problms if you have two concurrent GETs happening at once. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-19 by DrAzzy
How does the callback in an http request work? Why is there a second callback? I thought the callback supplied with the request would be called when the response was returned, yet this seems to be placing another callback waiting on... something...?
When does res.on() get called?
Does res.on('data') get called only once per request, or can it be called multiple times, each time with a piece of the data? If the latter is true, how do I know that i've got all the pieces?
The link in the http docs for more info on the node.js http api is dead - possibly when working this would explain it - but nodemanual.org seems to be down. http://nodemanual.org/latest/nodejs_ref_guide/http.html
The use case I've got in mind is - I want to fetch a file and evaluate it, and am wondering if I can safely do this, or whether sometimes the data won't be complete, hence the eval will fail.
Beta Was this translation helpful? Give feedback.
All reactions