I read: Design pattern for managing multiple asynchronous JavaScript operations but this does not have a clear resolution and also the question is very old and jQuery dependent.
My situation is somewhat similar, it can not be resolved with promise.all as the asynchronous task is being invoked by a users as often as they like, as frequently as they like.
What I am trying to do is see when all async operations are idle. When is asyncTest truly doing nothing.
This has got to be a common check, just wondering how it is done.
The user can invoke asyncTest at anytime.
class TestApp {
processing = false;
asyncTest() {
this.processing = true;
setTimeout(() => {
this.processing = false;
}, 500);
}
}
As you can see this will have collisions.
Other async tasks may want to see if this is processing. I considered the following but it just feels so darn hacky
EDIT: Well, based on comments by Simon K below and the fact that it is clean and working, until I hear otherwise from the community, my original solution below seems to be fine:
class TestApp {
_processCount = 0;
get isProcessing() {
return this._processCount > 0;
}
asyncTest() {
this._processCount++;
setTimeout(() => {
this._processCount--;
}, 500);
}
}
Note: Angular 5 Project. Somewhat familiar with Rx/js but not so pro with it, I recently realized how powerful it is and have a suspicion it would help here.
Many Thanks!