Currently, I am utilizing a node library that facilitates simple HTTP requests and returns promises. This method works well for me as it allows multiple requests to be made simultaneously, which I can then gather later using Promise.all()
. However, the challenge lies in the fact that each HTTP request only returns a string, whereas I also require additional identifying information about each request.
To address this issue, my approach involves extending the request promise chain to include the necessary information. Below is an example of how I am adding one such request to the array of promises:
var promises = [];
promises.push(new Promise(function(resolve, reject){
ReqPromise('http://some.domain.com/getresult.php')
.then(function(reqResult) {
resolve({
source: 'identifier',
value: reqResult
});
});
}));
When this particular promise resolves, this is the output:
{
source: 'identifier'
value: 1.2.3.4
}
Do you think this method of tagging a promise result is optimal or is there perhaps a misunderstanding on my part regarding promises that eliminates the need for creating an additional promise as demonstrated above? It is worth noting that ReqPromise
is from an external library, making it challenging to modify its behavior to accept and return extra parameters.