How JavaScript determines that a Promise has settled

In the following code how does JavaScript determine that the state of myPromise has become “fulfilled”? I.e., how is the determination made that it’s time to put the .then() handler into the microqueue for subsequent execution?

const myPromise = new Promise(function(resolve, reject) {
    setTimeout(function() {
        resolve('Resolved  promise: ');
    }, 2000);
});

myPromise.then((resolvedValue) => {
    console.log(resolvedValue + 'The .then() handler is now running');
});

// Output (after ~2 seconds): “Resolved promise: The .then() handler is now running”