I've got a weird behavior going on: I believe that...
# suitescript
m
I've got a weird behavior going on: I believe that I have promises executing sequentially, rather than "as fast as possible" See below:
Copy code
function myFunction(listOfThings) {
  return new Promise((resolve, reject) => {
    let promises = []
    for (let thing of Object.values(listOfThings)) {
      log.debug("What time is it?", new Date());
      promises.push(queryThatSystem(thing));
    }

    Promise.allSettled(promises).then((myPromise) => {
      // [Do stuff]
    }
  });
}

function queryThatSystem(thing) {
  return new Promise((resolve, reject) => {
    // [Do more stuff]
  });
}
Notice the log that I put in there. The output of that log has anywhere between 0.5 and 3 seconds of difference between each iteration of the loop, telling me that instead of just filling the array of promises and then letting them all execute at once, it seems that it's putting the promises in a queue, waiting for one of them to be done before getting to work on the other. My bet is that I structured my promises wrong and I'm missing something fundamental here, but I could use a second glance since I'm not too sure where I've erred in making that bit of code. 🤔
SOLVED. Not apparent in my simplified example is that
queryThatSystem()
notably ran a
https.request
. ...That is, not a
https.request.promise
. That one boo-boo caused the function to run synchronously instead of asynchronously. Switching the HTTPS request to a promise restored asynchronicity, and now my log traces clearly indicate that every iteration of the loop is running at the same time.
❤️ 1
👌 1
🎉 1
e
Nice; thanks for following up