type Handler < T > = ( data : T ) => void ; export default function EE < T > ( ) { let S = new Set < Handler < T > > ( ) ; return { listen : ( fn ) => { S . add ( fn ) ; } , unlisten : ( fn ) => { S . delete ( fn ) ; } , emit : ( data ) => { for ( let h of S ) h ( data ) ; } , } ; } export function LifeTimeNotify < T > ( ) { const ctx = { } ; ctx . promise = new Promise ( ( resolve ) => { ctx . resolve = resolve ; } ) ; function emit ( data ) { if ( ctx . resolve ) return ctx . resolve ( data ) ; setTimeout ( ctx . resolve , 1 , data ) ; } function once ( handler ) { ctx . promise . then ( handler ) ; } return [ emit , once ] ; }