import { BeDuration } from "@itwin/core-bentley" ; const recursiveWait = async ( pred , repeater ) => { if ( pred ( ) ) { await BeDuration . wait ( 0 ) ; await repeater ( ) ; } } ; internal export const waitForAllAsyncs = async ( handlers ) => { const pred = ( ) => handlers . some ( ( h ) => ( h . pendingAsyncs . size > 0 ) ) ; await recursiveWait ( pred , async ( ) => waitForAllAsyncs ( handlers ) ) ; } ; internal export const waitForPendingAsyncs = async ( handler ) => { const initialAsyncs = [ ... handler . pendingAsyncs ] ; const pred = ( ) => initialAsyncs . filter ( ( initial ) => handler . pendingAsyncs . has ( initial ) ) . length > 0 ; const recursiveWaitInternal = async ( ) : Promise < void > => recursiveWait ( pred , recursiveWaitInternal ) ; await recursiveWaitInternal ( ) ; } ;