Promise znotraj verige v JavaScript
Funkcije verige lahko tudi vračajo promise.
V tem primeru bo rezultat tega promisa prišel
v naslednji then:
promise.then(
function(result) {
return result + '1';
}
).then(
function(result) {
return new Promise(function(resolve) {
resolve(result + '2'); // ta rezultat bo prišel v naslednji then
});
}
).then(
function(result) {
return result + '3';
}
).then(
function(result) {
console.log(result); // izpiše 'string123'
}
);