whenWithTimeout
Like normal when, except that this when will automatically dispose if the condition isn't met within a certain amount of time.
Parameters
expractiontimeout(number): Maximum amountwhenspends waiting before giving up (optional. default:10000)onTimeout(any): Theontimeouthandler will be called if the condition wasn't met within the given time (optional. default:())
Returns
IDisposer: disposer function that can be used to cancel thewhenprematurely. NeitheractionoronTimeoutwill be fired if disposed.
Examples
test("expect store to load", t => {
const store = {
items: [],
loaded: false
}
fetchDataForStore((data) => {
store.items = data;
store.loaded = true;
})
whenWithTimeout(
() => store.loaded
() => t.end()
2000,
() => t.fail("store didn't load with 2 secs")
)
})