Région de recherche :

Date :

https://stackoverflow.com › questions › 27759593

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

The async function will still return a promise object if called without an await (or in non asynchronous code). Check the result of console.log (waitForPromise ()) if you are uncertain.

https://stackoverflow.com › questions › 28921127

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

I'm wondering if there is any way to get a value from a Promise or wait (block/sleep) until it has resolved, similar to .NET's IAsyncResult.WaitHandle.WaitOne (). I know JavaScript is single-threaded, but I'm hoping that doesn't mean that a function can't yield.

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

Wait for a Promise to Resolve before Returning in JS - bobbyhadz

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. index.js.

Wait for a Promise to Resolve before Returning in JS - bobbyhadz

https://www.delftstack.com › fr › howto › javascript › javascript-wait-for-function-to-finish

Comment attendre qu'une fonction se termine en JavaScript - Delft Stack

Ce tutoriel présente les fonctions JavaScript Callbacks, Promises et async/await et vous montre comment attendre la fin d’une fonction asynchrone avant de poursuivre l’exécution.

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

Using promises - JavaScript | MDN

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://developer.mozilla.org › fr › docs › Web › JavaScript › Guide › Using_promises

Utiliser les promesses - JavaScript | MDN

Promise.resolve () et Promise.reject () sont des méthodes qui permettent de créer des promesses déjà tenues ou rompues. Promise.all () et Promise.race () sont deux outils de composition qui permettent de mener des opérations asynchrones en parallèle.

https://webtips.dev › wait-for-function-to-finish-in-javascript

How to Wait for a Function to Finish in JavaScript - webtips.dev

Learn how you can use callbacks, promises and async/await to wait for function to finish in JavaScript.

How to Wait for a Function to Finish in JavaScript - webtips.dev

https://developer.mozilla.org › en-US › docs › Learn › JavaScript › Asynchronous › Promises

How to use promises - MDN Web Docs

A promise is an object returned by an asynchronous function, which represents the current state of the operation. At the time the promise is returned to the caller, the operation often isn't finished, but the promise object provides methods to handle the eventual success or failure of the operation.

https://www.freecodecamp.org › news › async-await-javascript-tutorial

Async Await JavaScript Tutorial – How to Wait for a Function to Finish ...

Async/Await lets us use generators to pause the execution of a function. When we are using async / await we are not blocking because the function is yielding the control back over to the main program. Then when the promise resolves we are using the generator to yield control back to the asynchronous function with the value from the ...

Async Await JavaScript Tutorial – How to Wait for a Function to Finish ...

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

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

To create a promise we need to use the Promise constructor function like this: const promise = new Promise(function(resolve, reject) { }); The Promise constructor takes a function as an argument and that function internally receives resolve and reject as parameters.