import EventEmitter from 'events' ; export default async function once < T > ( emitter , evt , timeout ) { return new Promise ( ( resolve , reject ) => { const listener = ( ret ) => { clearTimeout ( timer ) ; resolve ( ret ) ; } ; const timer = setTimeout ( ( ) => { emitter . removeListener ( evt , listener ) ; reject ( new Error ( 'Timeout' ) ) ; } , timeout ) ; emitter . once ( evt , listener ) ; } ) ; }