/* 
* How to use __request()
* step by step
*/

// create an array of URLs
var urls = ["http://www.example.com/firts", "http://www.example.com/second", "http://www.example.com/third"];

// execute the request
// and assign a callback
__request(urls, function(responses) {

	// When all the requests are ready
	// this callback will be called
	// you will get an argument, is
	// a map with all the responses
	// of the request you made,
	// something like this:
	/*
		responses = {
			"http://www.example.com/firts": {
				error: [object Object],
				response: [object Object],
				body: [object Object]
			},
			"http://www.example.com/second": {
				error: [object Object],
				response: [object Object],
				body: [object Object]
			},
			"http://www.example.com/third": {
				error: [object Object],
				response: [object Object],
				body: [object Object]
			}
		}
	*/


	// Acces to a response:

	// direct reference
	var first_response = response["http://www.example.com/first"];
		// check for errors of the first response
		console.log(first_response.error);
		// access to the body of the first response
		console.log(first_response.body);

	// also you can reuse the reference on the original array
	var first_response = response[urls[0]];


	// Iterate responses:

	// You can simply iterate all responses
	// to find errors or process the response
	var url, response;

	for (url in responses) {
		// reference to the response object
		response = responses[url];

		// find errors
		if (response.error) {
			console.log("Error", url, response.error);
			return;
		}

		// render body
		if (response.body) {
			console.log("Render", url, response.body);
		}
	}

});