I looked at HostPromiseRejectionTracker in the ECMAScript specification, but still did not understand what it was doing. It does not have specific steps of the algorithm, so it is not clear how this operation works in the current code.
One thing is clear that HostPromiseRejectionTracker is called when creating a new Promise when executing a function that calls the reject function. And the second time when "then" method is called for the first time, HostPromiseRejectionTracker is called only for the first time when "then" method is called.
For example, the first case occurs in such code
var promiseA = new Promise((resolve, reject) => {
setTimeout(() => reject(new Error("Text of Error")), 3000)
});
The second case occurs
var promiseA = new Promise((resolve, reject) => {
setTimeout(() => reject(new Error("Text of Error")), 3000)
});
promiseA.then();
But I don’t understand what HostPromiseRejectionTracker does exactly. Who understands what this operation is doing, explain its meaning, purpose and manifestation in the working ECMAScript code.