I'm using an API which provides an async method used like this:
api.isActive(function(err, active) {
// check for error
// use active boolean
});
The underlying object state is "volatile", i.e. it changes without any interaction from the program.
I'd like to wait for a given state - this will involve calling isActive repeatedly (with some interval) until the desired state is determined. The entire operation should be given a maximum amount of time for the state to be achieved before bailing out. An old-school nodejs callback(err) should be called with the completion (this can be promise-ified later).
I could write some code with setTimeout() but I'd prefer to use a canned solution or pattern, and lodash seems likely to provide something but I can't quite see what method could be used for this.
lodash doesn't have such function, cause it's can be done with setInterval easily
if you want some wait logic, try to look on https://github.com/luciotato/waitfor
but, anyway, you need to use setInterval / setTimeout for checks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With