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 amount when spends waiting before giving up (optional. default: 10000)
  • onTimeout (any): The ontimeout 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 the when prematurely. Neither action or onTimeout 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")
  )
})

results matching ""

    No results matching ""