import { RootState } from 'src/redux/reducers' import { call, delay, race, select, take } from 'typed-redux-saga' export function withTimeout any>( wait: number, fn: Fn, ...args: Parameters ) { return function* withTimeoutGen() { const { res, timeout } = yield* race({ res: call(fn, ...args), timeout: delay(wait), }) if (timeout) { // TODO(cmcewen): #2824 Handle failure case properly } return res } } export function* waitFor(selector: (state: RootState) => Value) { while (true) { const value: Value = yield* select(selector) if (value != null) { return value } yield* take('*') } }