“Promesse en js” 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

JS promet

console.log('some piece of code');
examplePromise.then(function(result){
  console.log(result);
}).catch(function (error) {
  console.error(error);
});
console.log('another piece of code');
Blue Beetle

promesse javascript

let promise = new Promise((resolve,reject)=>{
                try {
                    resolve("some data");
                } catch (error) {
                    reject(error);
                }
            })
            
            promise.then(function (data) {
                console.log(data);
            },function (error) {
                console.error(error);
            })
Powerful Pigeon

Objectif Promise JavaScript

let promise = new Promise(function(resolve, reject){
  try{
  	resolve("works"); //if works
  } catch(err){
    reject(err); //doesn't work
  }
}).then(alert, console.log); // if doesn't work, then console.log it, if it does, then alert "works"
Lonely Lyrebird

Programme JavaScript avec une promesse

const count = true;

let countValue = new Promise(function (resolve, reject) {
    if (count) {
        resolve("There is a count value.");
    } else {
        reject("There is no count value");
    }
});

console.log(countValue);
SAMER SAEID

Promesse en js

myPromise
.then(handleResolvedA)
.then(handleResolvedB)
.then(handleResolvedC)
.catch(handleRejectedAny)
.finally(handleComplition)
Suman Majhi

Réponses similaires à “Promesse en js”

Questions similaires à “Promesse en js”

Plus de réponses similaires à “Promesse en js” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code