param fn param delay param init return export function debounce < T extends ( ... args : any [ ] ) => any , R extends ( ... args : Parameters < T > ) => Promise < ReturnType < T > > > ( fn , delay , init = null ) { let flag ; let result = init ; return async function ( ... args ) { return new Promise ( ( resolve ) => { if ( flag ) { clearTimeout ( flag as any ) ; } flag = setTimeout ( ( ) => resolve ( ( result = fn ( ... args ) ) ) , delay ) as any ; setTimeout ( ( ) => resolve ( result ) , delay ) ; } ) ; } as R ; }