Ich habe eine Kette von Promise
wie unten Code. Ich möchte die dritte Promise
warten auf den Abschluss der zweiten, aber es ist nicht! Kann jemand das Problem erklären?Verkettung
var condition = true;
// Promise
var willIGetNewPhone = new Promise(
function (resolve, reject) {
if (condition) {
var phone = {
brand: 'Samsung',
color: 'black'
};
setTimeout(function(){
console.log("First Prommis!");
resolve(phone);
}, 2000)
} else {
var reason = new Error('Has not condition!');
reject(reason);
}
}
);
var showOff = function (phone) {
var message = 'Need New Phone ' +
phone.color + ' ' + phone.brand + ' phone';
setTimeout(function(){
console.log("Second promis!");
return Promise.resolve(message);
}, 1000)
};
willIGetNewPhone
.then(showOff)
.then(function (fulfilled) {
console.log("Third Pramis!");
})
.catch(function (error) {
console.log(error.message);
});