export async function promiseTimeout ( mSec , promise ) { const timeout = new Promise ( ( resolve , reject ) => { const id = setTimeout ( ( ) => { clearTimeout ( id ) ; reject ( new Error ( `Timed out in ${ mSec } milliseconds.` ) ) ; } , mSec ) ; } ) ; return Promise . race ( [ promise , timeout , ] ) ; }