If we have a promise like the following, what are the answers to the questions in its comments?
p.then(function ok () {
// Can we get err() to trigger from inside here?
}, function err () {
// Can we get ok() to trigger from inside here?
});
I know that one can attach a new then
which can wait for the results or reverse the results of p
, but I'm wondering, assuming that p
is constant, whether the conditions can call each other recursively also (and without assigning the functions to variables and invoking them by name)...
UPDATE
My use case is as follows.
In IndexedDB, when opening a database, you can listen for the following:
db.onsuccess = ...
db.onerror = ...
db.onblocked = ...
db.js, a library I'm expanding to meet my needs, adds these events with a Promise API, such that a success will resolve the promise, and errors or blocking will reject it.
A common use case for listening for blocking would be to close the database connection which is causing the blocking and IndexedDB will thereupon automatically call onsuccess
. The problem is that if we treat onblocked
as a rejection, it apparently has no way to retrigger the resolve condition (i.e., the onsuccess
). In order to get around this, I can have the blocking be supplied instead as a callback, but I was wondering whether there were any way to do it exclusively using the Promises approach since technically, the error would no longer be an error and would like to give a chance for the original resolve callback to resume with its handling of success.