When using Promises, why can't triggers for resolve
and reject
be defined elsewhere in the codebase?
I don't understand why resolve
and reject
logic should be localized where the promise is declared. Is this an oversight, or is there a benefit to mandating the executor
parameter?
I believe the executor function should be optional, and that its existence should determine whether the promise encapsulates resolution or not. The promise would be much more extensible without such mandates, since you don't have to initiate async right away. The promise should also be resettable. It's a 1 shot switch, 1 or 0, resolve()
or reject()
. There are a multitude of parallel and sequential outcomes that can be attached: promise.then(parallel1)
and promise.then(parallel2)
and also promise.then(seq1).then(seq2)
but reference-privileged players cannot resolve/reject INTO the switch
You can construct a tree of outcomes at a later time, but you can't alter them, nor can you alter the roots (input triggers)
Honestly, the tree of sequential outcomes should be edittable as well.. say you want to splice out one step and do something else instead, after you've declared many promise chains. It doesn't make sense to reconstruct the promise and every sequential function, especially since you can't even reject or destroy the promise either...