I have this situation in which I would like to know what the status is of a promise. Below, the function start
only calls someTest
if it is not running anymore (Promise is not pending). The start
function can be called many times, but if its called while the tests are still running, its not going to wait and returns just false
class RunTest {
start() {
retVal = false;
if (!this.promise) {
this.promise = this.someTest();
retVal = true;
}
if ( /* if promise is resolved/rejected or not pending */ ) {
this.promise = this.someTest();
retVal = true;
}
return retVal;
}
someTest() {
return new Promise((resolve, reject) => {
// some tests go inhere
});
}
}
I cannot find a way to simply check the status of a promise. Something like this.promise.isPending
would be nice :) Any help would be appreciated!