Find answers, ask questions, and connect with our
community around the world.

Forums Forums Web Design .then() for better performance than await

  • .then() for better performance than await

    updated 5 days, 22 hours ago 0 Member · 1 Post
  • BusinessMag

    September 22, 2022 at 6:03 pm

    I’m curious if it makes sense to make use of .then() more than await to get better performance. Especially when dealing with an array of requests. For example, I just wrote a script to move my blog to a new database. So I have something like the below where I’m taking a JSON response from the previous database and using it to add the blog to the new database. const promises = []; for (json of jsonArray) { promises.push( prisma.image.findFirst({where: …}).then(imageData => { return{…imageData, ..json}) } } await Promise.all(promises) So you can see the basic idea is to build and link promises and only await at the very end. I have to get the image first, then use the response from that call to add that specific image to the new blog. This queues everything up in the correct order and the performance seems to be much better. I wondering if this is the best way to go about this. Or if there is a cleaner way of doing this without too much chaining. Especially given a system where this may go much deeper with a lot of relationships. Obviously Prisma’s createMany can probably handle this, but I’m more curious about this form of linking promises together. – by /hq/Gold-Caterpillar-794 – –

Viewing 1 of 1 replies
Reply to: BusinessMag
Your information:

Original Post
0 of 0 posts June 2018