जावास्क्रिप्ट में चेन के अंदर प्रॉमिसेस
चेन फ़ंक्शन प्रॉमिसेस भी वापस कर सकते हैं।
इस स्थिति में, इस प्रॉमिस का परिणाम अगले
then में चला जाएगा:
promise.then(
function(result) {
return result + '1';
}
).then(
function(result) {
return new Promise(function(resolve) {
resolve(result + '2'); // यह परिणाम अगले then में जाएगा
});
}
).then(
function(result) {
return result + '3';
}
).then(
function(result) {
console.log(result); // 'string123' आउटपुट करेगा
}
);