Various implementations of promise maintain an array _ deferreds that holds the callback function set registered by the then method. When will this array reach 2 items?

I have reviewed articles of various promise implementations, all of which indicate that it is necessary to maintain a _ deferreds to save the callback function set information registered by the then method, and some implementations maintain onResolvedCallback and onRejectedCallback to maintain.

but many don"t explain why _ deferreds needs to be an array. Or the description of _ deferreds is relatively vague, and I can"t understand it directly until I get home with the technology.

for example, in this article
the author says that the then method can be called multiple times by the same promise, so it needs to be initialized to an array. I don"t know when the then method will be called multiple times by the same promise.

ask for a code to illustrate this situation!

Mar.07,2021

if I need to execute Task 1 and Task 2 after 3 seconds, it will be written in the following form

function f1(){}
function f1(){}
var promise = new Promise((resolve) => {
    setTimeout(resolve, 3000)
})
promise1.then(f1)
promise1.then(f2)
Menu