license import { Observable , } from 'indefinite-observable' ; import { MockRAF , } from './useMockedRAF' ; export type ExhaustValuesArgs = { state$ : Observable < 'active' | 'at_rest' > ; mockRAF : MockRAF ; } ; export function exhaustValues ( { state$ , mockRAF } ) { let triesLeft = 50 ; let hasBeenActive ; let isAtRest ; state$ . subscribe ( ( state ) => { if ( state === 'active' ) { hasBeenActive = true ; } if ( state === 'at_rest' && hasBeenActive ) { isAtRest = true ; } } ) ; while ( ! isAtRest && triesLeft > 0 ) { mockRAF . step ( ) ; triesLeft -- ; } } export default exhaustValues ;