let mousePromise ; let mousePromiseResolve ; let manualPromise ; let manualPromiseResolve ; window . addEventListener ( "mousedown" , down , true ) ; window . addEventListener ( "mouseup" , up , true ) ; function up ( ) { if ( mousePromiseResolve ) { mousePromiseResolve ( ) ; } mousePromise = null ; mousePromiseResolve = null ; } function down ( ) { if ( mousePromise && mousePromiseResolve ) { mousePromiseResolve ( ) ; } mousePromise = new Promise ( ( res ) => { mousePromiseResolve = res ; } ) ; } export function continueOnIdle ( ) { return Promise . all ( [ mousePromise || Promise . resolve ( ) , manualPromise || Promise . resolve ( ) , ] ) ; } export function setBusy ( ) { if ( manualPromise ) { return ; } manualPromise = new Promise ( ( res ) => { manualPromiseResolve = res ; } ) ; } export function setIdle ( ) { manualPromiseResolve && manualPromiseResolve ( ) ; manualPromise = null ; }