“Créer une promesse en javascript” Réponses codées

promesses javascript

var promise = new Promise(function(resolve, reject) {
  // do some long running async thing…
  
  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  }
  else {
    reject(Error("It broke"));
  }
});

//usage
promise.then(
  function(result) { /* handle a successful result */ },
  function(error) { /* handle an error */ }
);
Grepper

Faire des promesses

new Promise((resolve, reject) => {
  if (ok) { resolve(result) }
  else { reject(error) }
})
 
Motionless Mallard

Promise JavaScript

const promiseA = new Promise( (resolutionFunc,rejectionFunc) => {
    resolutionFunc(777);
});
// At this point, "promiseA" is already settled.
promiseA.then( (val) => console.log("asynchronous logging has val:",val) );
console.log("immediate logging");

// produces output in this order:
// immediate logging
// asynchronous logging has val: 777
Tender Teira

Créer une promesse en javascript

async function abc() 
{ 	
	const myPromise = new Promise(function(resolve, reject) {
   resolve("hello world");
});
let y= await myPromise;
console.log(y);
/*"hello world*/
	}
Javasper

Réponses similaires à “Créer une promesse en javascript”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code