Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Using Promise.race | Mastering Promises
Asynchronous JavaScript Explained

bookUsing Promise.race

script.js

script.js

index.html

index.html

copy

When you need to move forward as soon as the fastest asynchronous task completes, you can use Promise.race. This method takes an array of Promises and returns a new Promise that settles as soon as any of the input Promises settles, whether that means resolving or rejecting. The returned Promise adopts the state and value (or reason) of the first Promise to settle. This makes Promise.race useful when you care only about the result of the quickest operation, such as the fastest response from multiple servers or the first completed user action. Unlike Promise.all, which waits for every Promise to finish, Promise.race moves on as soon as one finishes—regardless of whether it succeeded or failed.

question mark

When does Promise.race resolve or reject?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 8

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you give an example of how to use Promise.race in code?

What happens if the first Promise to settle is rejected?

How is Promise.race different from Promise.allSettled?

Awesome!

Completion rate improved to 3.57

bookUsing Promise.race

Swipe um das Menü anzuzeigen

script.js

script.js

index.html

index.html

copy

When you need to move forward as soon as the fastest asynchronous task completes, you can use Promise.race. This method takes an array of Promises and returns a new Promise that settles as soon as any of the input Promises settles, whether that means resolving or rejecting. The returned Promise adopts the state and value (or reason) of the first Promise to settle. This makes Promise.race useful when you care only about the result of the quickest operation, such as the fastest response from multiple servers or the first completed user action. Unlike Promise.all, which waits for every Promise to finish, Promise.race moves on as soon as one finishes—regardless of whether it succeeded or failed.

question mark

When does Promise.race resolve or reject?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 8
some-alt