whenWithTimeout
Like normal when
, except that this when
will automatically dispose if the condition isn't met within a certain amount of time.
Parameters
expr
action
timeout
(number
): Maximum amountwhen
spends waiting before giving up (optional. default:10000
)onTimeout
(any
): Theontimeout
handler 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 thewhen
prematurely. Neitheraction
oronTimeout
will 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")
)
})