I am familiar with the strength of an asynchronous execution, and I know how to use callbacks. Though, for few reasons, I wish to execute some portion of code in a synchronized manner. For instance, http.get() and child_process.exec().
Note that both examples mentioned above must be utilized with event listeners (on(...)) in order to collect results and handle errors.
Any chance that one could shed light on the issue.
A small snippet will be great (for instance, synchronized http.get() with its even handling)
Thanks.
UPDATE: I am able to use httpsync in order to produce a request and capture the response. The response itself is a buffer. I am using httysync to retrieve few images, but when writing the buffer to file (using fs.writeFile), the image can not be open. I guess it has to do with some conversion of the file. So if one can help with solving this, then it solves the issue.
enclosed a snippet
var httpsync = require("httpsync");
var fs = require("fs");
var req = httpsync.get({ url : "http://www.tunisia-live.net/wp-content/uploads/2011/12/christmas-tree-wallpaper1024x768.jpg" });
var res = req.end();
fs.writeFile("out.jpg", res.data, function(err) {
if (err)
console.log(err);
});