Région de recherche :

Date :

https://stackoverflow.com › questions › 28921127

asynchronous - How to wait for a JavaScript Promise to resolve before ...

Code below shows how to wait for all the promises to resolve and then deal with the results once they are all ready (as that seemed to be the objective of the question); Also for illustrative purposes, it shows output during execution (end finishes before middle).

https://stackoverflow.com › questions › 27759593

javascript - How do I wait for a promise to finish before returning the ...

Use async/await (NOT Part of ECMA6, but available for Chrome, Edge, Firefox and Safari since end of 2017, see canIuse) MDN. async function waitForPromise() {. // let result = await any Promise, like: let result = await Promise.resolve('this is a sample promise'); }

https://bobbyhadz.com › blog › javascript-wait-promise-resolve-before-returning

Wait for a Promise to Resolve before Returning in JS

Learn different ways to use async/await, then(), or setTimeout() to wait for a promise to resolve before returning in JavaScript. See examples, code snippets, and explanations of promise states and handling errors.

Wait for a Promise to Resolve before Returning in JS

https://developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › await

await - JavaScript | MDN - MDN Web Docs

The await operator is used to wait for a Promise and get its fulfillment value. It can only be used inside an async function or at the top level of a module.

https://www.delftstack.com › howto › javascript › javascript-wait-for-promise-to-resolve

How to Wait for Promises to Get Resolved in JavaScript

Promise takes two arguments, resolve and reject. The resolve() method returns a promise object that is resolved with a value. If there is an error while executing a promise, the reject method will return an error. Promises use async and await keywords.

https://www.delftstack.com › fr › howto › javascript › javascript-wait-for-promise-to-resolve

Attendez que les promesses soient résolues en JavaScript

La promesse prend deux arguments, résoudre et rejeter. La méthode resolve() renvoie un objet de promesse qui est résolu avec une valeur. S’il y a une erreur lors de l’exécution d’une promesse, la méthode de rejet renverra une erreur. Les promesses utilisent les mots-clés async et wait.

https://www.freecodecamp.org › news › javascript-promises-async-await-and-promise-methods

How to Use JavaScript Promises – Callbacks, Async/Await, and Promise ...

So when we use the Promise.race method, it will wait until the first promise gets resolved or rejected and then: If the first promise in the promise chain gets resolved, the .then handler will be executed and the result will be the result of the first resolved promise.

How to Use JavaScript Promises – Callbacks, Async/Await, and Promise ...

https://javascript.info › async-await

Async/await - The Modern JavaScript Tutorial

The keyword await makes JavaScript wait until that promise settles and returns its result. Here’s an example with a promise that resolves in 1 second: async function f() { let promise = new Promise((resolve, reject) => { setTimeout(() => resolve("done!"), 1000) }); let result = await promise; alert(result); // "done!" } f();

https://developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Using_promises

Using promises - JavaScript | MDN - MDN Web Docs

const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); wait(10 * 1000) .then(() => saySomething("10 seconds")) .catch(failureCallback); The promise constructor takes an executor function that lets us resolve or reject a promise manually.

https://ourcodeworld.com › ... › read › 1544 › how-to-implement-a-timeout-for-javascript-promises

How to implement a timeout for JavaScript Promises

The first solution involves the Promises.race method. This built-in method returns the result (or the rejection) of the first promise that is fulfilled, while the others will be ignored. In the case of a timeout-like implementation, you may implement something like this: // 1. Your original promise that runs custom logic.