as shown in the below posted code, for the array geoTIFFsFileNames
it contains five files’ names. for the number of items in the latter array, i want to invoke the webservice
WSGeoTIFFAsBlobStreamer
, and for each invokation to it there are some data to be returned correspond to the file name.
i want to have the executions or the invokations to the webservice to be done async, so i created the array promises
to collect the promises returned from .stream
then, i executed all the pushed promises as follows:
await Promise.all(promises)
i expected that the response
in the .then()
of await Promise.all(promises)
is to contain all the responses for the five times invokations to the webservice, but at run time,
the response
in the .then()
of await Promise.all(promises)
contains only one response.!! i expected to have five responses where there is a response to be returned for each
time the webservice is invoked
please let me know how the code can be modified so the the response
in the .then()
of await Promise.all(promises)
returns five responses as the webservice gets invoked five
times
code:
const promises = new Array();
promises.push(geoTIFFsFileNames.map((geoTIFFFileName, index) => {
this.#geoTIFFOverlayBlobStreamingStates.value = GeoTIFFOverlayBlobStreamingStates.CONST_STREAMING.description;
this.#wsGeoTIFFAsBlobStreamer = new WSGeoTIFFAsBlobStreamer(geoTIFFFileName);
this.#wsGeoTIFFAsBlobStreamer.setRequestOptionsParams();
return this.#wsGeoTIFFAsBlobStreamer.stream((geoTIFFFileName, asBlob, asURL, state) => {
this.#msg = ({msg:infoTag + 'connectWSGeoTIFFsAsBlobsStreamerFor().',
url: `${endPointsURLs.VUE_NEWSWM_APP_LOCAL_HOST_3000.description}${endPointsURLs.VUE_NEWSWM_APP_PATH.description}${BackendWssConstants.CONST_WS_GEOTIFF_AS_BLOB_STREAMER.description}/${geoTIFFFileName}`,
asBlob: asBlob,
asURL: asURL,
state: state,
});
console.info(this.#msg);
return [geoTIFFFileName, asBlob, asURL, state];
})
}));
await Promise.all(promises)
.then(response => {
this.#msg = {msg:verboseTag + 'xcx connectWSGeoTIFFsAsBlobsStreamerFor().', response: response};
console.log(this.#msg);
this.#geoTIFFOverlayBlobStreamingStates.value = GeoTIFFOverlayBlobStreamingStates.CONST_BLOB_OBTAINED.description;
this.#setWSGeoTIFFAsBlobStreamerResults({
order: order,
geoTIFFFileName: response[0],
asBlob: response[1],
asURL: response[2],
state: response[3],
});
resolve(response);
onResult(response[0], response[1], response[2], response[3]);
})
.catch(err => {
this.#geoTIFFOverlayBlobStreamingStates.value = GeoTIFFOverlayBlobStreamingStates.CONST_ERROR_OCCURED.description;
this.#msg = JSON.stringify({msg:WTFTag + 'connectWSGeoTIFFsAsBlobsStreamerFor.value. Error impeded ws from successful execution and return:',
ws:BackendWssConstants.CONST_WS_GEOTIFF_AS_BLOB_STREAMER.description,
geoTIFFsFileNames: geoTIFFsFileNames,
error: err,
});
console.error(this.#msg);
reject({msg:errorTag + 'faild to fetch: ' + BackendWssConstants.CONST_WS_GEOTIFF_AS_BLOB_STREAMER.description + ' rejected promise', err:err});
onResult(null, null, null);
throw new Error(this.#msg);
});
Promise.all()
returns an Array
with the response of each of the Promise
s in the respective order.