O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multiple requests in parallel

Executing multiple parallel requests becomes a piece of cake with async/await. Here, we can execute several asynchronous tasks at once, and use their values in different places. The complete source code can be found at multiple_parallel.ts in src:

async function executeParallelAsyncTasks() {  const [valueA, valueB, valueC] = await    Promise.all([            await axios.get('https://jsonplaceholder.typicode.com/posts/1')            await axios.get('https://jsonplaceholder.typicode.com/posts/2'),            await axios.get('https://jsonplaceholder.typicode.com/posts/3')])            console.log("first response is ", valueA.data);            console.log(" second response is ", valueB.data);            console.log("third response is ", valueC.data);      }

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required