I would like to know how I can do dynamic fetch requests in parallel, I have been trying to do this for 12 hours and I cant figure it out, I looked everywhere on google and StackOverflow, I really am tired.
for (const fileindex of filelist) {
let dcmFilename = `slice_${fileindex}.dcm`
slices.push( {index:fileindex, filename:dcmFilename} )
fd.append(dcmFilename, files[fileindex], dcmFilename);
fd.append('slices', JSON.stringify(slices));
loopcount += 1
if (filecount == 24 || loopcount == filelist.length){
if (cursorPos !== false) {
let scaleFactor = Tegaki.scaleFactor;
cursorPos.x = parseInt(cursorPos.x / scaleFactor);
cursorPos.y = parseInt(cursorPos.y / scaleFactor);
fd.append('x', cursorPos.x);
fd.append('y', cursorPos.y)
}
// Get layer id from index
if (index !== -1) {
type = this.layerTypes[index]['id']
}
// switch mode from heuristic to pytorch vertebrae for vertebral bone
if (type === 'vertebral-bone' ){
mode='PyTorch-Vertebrae'
}
// Post to endpoint
let domain = window.location.origin.replace(':8080', ':5000')
let list = await fetch(`${domain}/segment?mode=${mode}&type=${type}`, { method: 'POST', body: fd })
let result = await list.json()
// do something with result
// finish then continue the loop and create new body and send a new request
// clear formdata and continue loop
fd = new FormData()
}
I have the following fetch request that I send, where the body is generated for each request, It's never the same body, the body gets generated dynamically by the functions. Is there a way to send all the requests at once, then wait for them to return a response, then proceed with the rest of my code?