Method that must return true in order for the intended function to fire.
Expected function. This method will fire after the resolver returns true.
Options that dictate timeout how the waitfor class behaves.
Sets the time the method was originally attempted. This is used to determine timeout.
How often should we poll and check the resolver if it didn't immediately return true.
Expected function. This method will fire after the resolver returns true.
Options that dictate timeout how the waitfor class behaves.
Method that must return true in order for the intended function to fire.
If set to true then rather than throwing an error at timeout the class will simply stop trying to resolve the resolver.
After this value has been exceeded the check will fail and stop trying.
Reference for the timer method, unless the request is immediately resolved
Returns the amount of time, in milliseconds, that has elapsed since the original request.
Takes the amount of time that has elapsed since originally requested and determines if the call should time out.
Clears the internal polling timer.
Starts the request to the resolver, and if needed the polling timer.
Utility method used to create the polling timer. It subsequently invokes, and clears the timer, or clears the timer and times out if the request has timed out.
Helper method to require less 'boilerplate'.
import { WaitFor } from 'waitfor.ts';
function resolverFn(): boolean {
// after something happens to set it true
return true;
}
function delayedFn(name) {
console.log(`Hello ${name}!`);
}
const DelayedFn = WaitFor.create(resolveFn, delayedFn);
DelayedFn('John') // "Hello John!" after resolver passes
Generated using TypeDoc
Utility to poll a resolver in order to determine if a function should fire. If the resolver does not pass before a timeout then the intended method will be undefined.
import WaitFor from 'waitfor.ts'; let user; function resolver() { return user !== undefined; } function WelcomeMessage(greet){ console.log(`${greet} ${user}!`); } const Wait = new WaitFor(resolver, WelcomeMessage); Wait.fire('Welcome'); // nothing yet // Pretend Login after some validation and stuff user = `Ben`; // Welcome Ben!