Esimorp
Inside Out Promises.
The simplest, yet handy, resolvable and rejectable Promises for all developers use cases.
// The constructor callback is optional.// If provided, it's exactly the same// that you would pass to a new Promise.const promise = ; // you can already use the instance// just like any other Promisepromise ; // ... and whenever it happens ...promise;
F.A.Q.
- can I
promise.then().resolve()
? Nope, only the initial resolvable creator/owner can resolve it. No side effects at distance. - can I safely pass around a
promise.then()
? Absolutely, that just creates a newPromise
copy that's not resolvable. - how can I abort an operation ? It's up to you, but following there is an example.
{ const p = ; const xhr = ; // derive from Esimorp // to avoid external resolution const out = p; // expose only abort, delegating to xhr outabort = xhrabort; // resolve indirectly out through Esimorp p xhr; xhr; xhr; // perform the operation xhr; xhr; // return the Promise with abort delegate return out;}
- what else could I do with this ? You could create Promises with a timeout and resolve or reject them before.
const p = { // reject in 5 seconds ;}; // but if resolved or rejected first is OK;
License
(C) 2017 Andrea Giammarchi, @WebReflection, MIT Style License.