export function addTimeout < T > ( target , msg , msTimeout = 1000 ) { const timeout = new Promise ( ( _resolve , reject ) => { const err = new Error ( msg ) ; const timer = setTimeout ( ( ) => { reject ( err ) ; } , msTimeout ) ; const cancel = clearTimeout . bind ( null , timer ) ; target . finally ( cancel ) ; } ) ; return Promise . race ( [ target , timeout ] ) as Promise < T > ; }