Région de recherche :

Date :

https://stackoverflow.com › questions › 28921127

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

Another option is to use Promise.all to wait for an array of promises to resolve and then act on those.

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

Wait for a Promise to Resolve before Returning in JS

You can use the async/await syntax or call the .then() method on a promise to wait for it to resolve. Inside functions marked with the async keyword, you can use await to wait for the promises to resolve before continuing to the next line of the function.

Wait for a Promise to Resolve before Returning in JS

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

How to Wait for Promises to Get Resolved in JavaScript

Promises in JavaScript allow us to wait for such operations or tasks to complete their execution, and based on whether the task is fulfilled, we can take further actions. We must create a Promise class object using the new keyword to use promises. Promise takes two arguments, resolve and reject.

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 › 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://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://www.freecodecamp.org › news › javascript-promises-async-await-and-promise-methods

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

A promise represents an asynchronous operation whose result will come in the future. Before ES6, there was no way to wait for something to perform some operation. For example, when we wanted to make an API call, there was no way to wait until the results came back.u0010.

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

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

Using promises - JavaScript | MDN - MDN Web Docs

A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of already-created promises, this guide will explain consumption of returned promises before explaining how to create them.

https://byby.dev › js-wait-for-multiple-promises

How to wait for multiple promises in JavaScript - byby.dev

You can use promises with async/await by declaring an async function and using the await keyword before a call to a function that returns a promise. This makes the code wait at that point until the promise is settled, meaning it is either fulfilled or rejected.

https://javascript.info › task › delay-promise

Delay with a promise - The Modern JavaScript Tutorial

Delay with a promise. The built-in function setTimeout uses callbacks. Create a promise-based alternative. The function delay(ms) should return a promise. That promise should resolve after ms milliseconds, so that we can add .then to it, like this: function delay(ms) { // your code } delay(3000).then(() => alert('runs after 3 seconds')); solution.