onSettled
Registers onSettled on value the way await value attaches to it. It is called once, with the value and a null error on success, or with undefined and the reason on failure.
A promise is watched directly, without calling its then. For any other thenable, then is read once and called from a microtask, as the Promise resolve functions do, and a promise or thenable it resolves with is followed to the end, so the callback is never handed one. A then getter or a then call that throws is a failure. Returns false, registering nothing, when value is not thenable at all, which await would hand straight back.
The callback runs from the microtask queue, which every outermost call into the engine drains as it returns, this one included, so for a promise that has already settled it runs before this returns. An exception it throws comes out of the call that drained the queue.