Explain Promise.race() with async-await in JavaScript Last Updated : 09 Jan, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will try to understand how we may implement Promise.race() method with async-await in JavaScript with the help of certain coding examples as well as theoretical explanations. Let us first quickly understand how we may implement Promise.race() method. This method is one of the most commonly used promise methods that state whichever promise will reach its end, first will be executed first and the rest will remain not executed. This may also be realized in real terms as whoever will reach first in the race will win the race, here also the concept remains the same. Syntax: The following syntax will help us to understand how we may implement Promise.race() method: Promise.race([first_promise , second_promise, ...]).then( // do something...... ) Let us see the following example for a better understanding of the above-illustrated Promise.race() method's syntax: Example 1: In this example, we will be creating three promises one after another with a timer function (setTimeout() method) inside each one of them. Each timer function would have different timings which will be mentioned at the end of their illustration. Then we will use Promise.race() method which will take all three promises as input in the form of an array and executes them as per its own role. JavaScript let first_promise = new Promise((resolve, reject) => { setTimeout(() => { resolve("GeeksforGeeks...!!"); }, 1000); }); let second_promise = new Promise((resolve, reject) => { setTimeout(() => { resolve("JavaScript......!!"); }, 2000); }); let third_promise = new Promise((resolve, reject) => { setTimeout(() => { resolve("TypeScript...!!"); }, 3000); }); let promise_array = [first_promise, second_promise, third_promise]; Promise.race(promise_array).then((result) => console.log(result)); Output: GeeksforGeeks...!! Now that we have understood how we may execute Promise.race() method, let us see the following example which will help us to understand how we may implement Promise.race() method with async-await keywords. Example 2: Like in the previous example, here we will be creating three promises, each having different timer functions with different timeouts. Then we will create a function (or a method) having prefix as async and inside it, we will store the result using another keyword called await then we will display the result with the help of then() method. JavaScript let first_promise = new Promise((resolve, reject) => { setTimeout(() => { resolve("GeeksforGeeks...!!"); }, 1000); }); let second_promise = new Promise((resolve, reject) => { setTimeout(() => { resolve("JavaScript......!!"); }, 2000); }); let third_promise = new Promise((resolve, reject) => { setTimeout(() => { resolve("TypeScript...!!"); }, 3000); }); async function displayResult() { let promise_array = [first_promise, second_promise, third_promise]; let result = await promise_array; Promise.race(promise_array).then((result) => console.log(result)); } displayResult(); Output: GeeksforGeeks...!! Comment More infoAdvertise with us Next Article Explain Promise.race() with async-await in JavaScript amansingla Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Methods JavaScript-Questions Similar Reads Explain Promise.any() with async-await in JavaScript In this article, we will try to understand how to implement the Promise.any() method with async-await in JavaScript using some theoretical explanations followed by some coding examples as well. Let us firstly quickly understand the working of Promise.any() method with some theoretical examples (incl 4 min read Explain Promise.all with async-await in JavaScript In JavaScript, Promise.all with async-await is used to handle multiple asynchronous operations concurrently. By combining Promise.all with await, you can wait for all promises to resolve or any to reject, ensuring that all asynchronous tasks are complete before proceeding with the next code executio 4 min read Explain Promise.allSettled() with async-await in JavaScript In this article, we will try to understand how we may implement the Promise.allSettled() method with async-await in JavaScript with the help of certain coding examples as well as theoretical explanations. Let us first quickly understand about Promise.allSettled() method. This method is one of the mo 3 min read Explain Async Await with Promises in Node.js Async/Await in Node.js is a powerful way to handle asynchronous operations. It allows you to write asynchronous code in a synchronous manner, making it easier to read, write, and debug. This feature is built on top of Promises, which represent a value that may be available now, or in the future, or 4 min read How to delay a loop in JavaScript using async/await with Promise ? In JavaScript, you can delay a loop by using async/await with Promise. By wrapping a setTimeout() inside a Promise and using await, you can pause execution at each iteration, creating delays between loop iterations for asynchronous tasks without blocking the main thread.What is async and await?async 2 min read How to use async/await with forEach loop in JavaScript ? Asynchronous is popular nowadays because it gives functionality of allowing multiple tasks to be executed at the same time (simultaneously) which helps to increase the productivity and efficiency of code. Async/await is used to write asynchronous code. In JavaScript, we use the looping technique to 2 min read How to set Maximum Execution Time for a Promise Await in JavaScript ? In JavaScript, asynchronous operations are more common, often implemented using promises and async/await syntax. However, there are certain scenarios where we want to set the execution times for these asynchronous operations to prevent them from running indefinitely. In this article, we'll explore v 3 min read JavaScript Promise Chaining Promise chaining allows you to execute a series of asynchronous operations in sequence. It is a powerful feature of JavaScript promises that helps you manage multiple operations, making your code more readable and easier to maintain.Allows multiple asynchronous operations to run in sequence.Reduces 3 min read Promise vs Callback in JavaScript In JavaScript, managing asynchronous operations is a key aspect of modern web development. Two popular approaches for handling these operations are Promises and Callbacks. While both techniques are designed to deal with tasks that take time to complete (like fetching data from a server), they work d 5 min read Async and Await in JavaScript Async and Await in JavaScript are used to simplify handling asynchronous operations using promises. By enabling asynchronous code to appear synchronous, they enhance code readability and make it easier to manage complex asynchronous flows.JavaScriptasync function fetchData() { const response = await 3 min read Like