javascript - Can a promise resolver/rejecter trigger its opposite? -


if have promise following, answers questions in comments?

p.then(function ok () {     // can err() trigger inside here? }, function err () {     // can ok() trigger inside here? }); 

i know 1 can attach new then can wait results or reverse results of p, i'm wondering, assuming p constant, whether conditions can call each other recursively (and without assigning functions variables , invoking them name)...

update

my use case follows.

in indexeddb, when opening database, can listen following:

db.onsuccess = ... db.onerror = ... db.onblocked = ... 

db.js, library i'm expanding meet needs, adds these events promise api, such success resolve promise, , errors or blocking reject it.

a common use case listening blocking close database connection causing blocking , indexeddb thereupon automatically call onsuccess. problem if treat onblocked rejection, apparently has no way retrigger resolve condition (i.e., onsuccess). in order around this, can have blocking supplied instead callback, wondering whether there way exclusively using promises approach since technically, error no longer error , give chance original resolve callback resume handling of success.

can err() trigger ok?
can ok() trigger err?

no. promises spec mandates @ 1 of 2 then handlers gets called. if promise fulfills first gets called, if promise rejects second will, , promise can't both things.

so while create 2 named functions , call each other manually, not programmatically possible trigger promise calling other.

my use case follows […]

what seem looking is

db.open().catch(function(err) {     if (err.isblocking)         return db.closeandwaitfornextsuccess(err.blocker); // promise     else         throw err; }).then(function ok(res) {     … }); 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -