JavaScript-də zəncir içində Promise-lər
Zəncir funksiyaları həmçinin Promise də qaytara bilər.
Bu halda bu Promise-in nəticəsi
növbəti then-ə düşəcək:
promise.then(
function(result) {
return result + '1';
}
).then(
function(result) {
return new Promise(function(resolve) {
resolve(result + '2'); // bu nəticə növbəti then-ə düşəcək
});
}
).then(
function(result) {
return result + '3';
}
).then(
function(result) {
console.log(result); // 'string123' çap edəcək
}
);