You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constEmittery=require('emittery')consteventEmitter=newEmittery()asyncfunctionasyncFunction(){thrownewError('Async function error')}eventEmitter.on('callAsyncFunction',asyncFunction)construnAsyncFunction=async()=>{try{awaiteventEmitter.emit('callAsyncFunction')}catch(e){console.log(e)}}runAsyncFunction()// Works as expected and prints 'Async function error'.functionsyncFunction(){thrownewError('Sync function error')}eventEmitter.on('callSyncFunction',syncFunction)try{eventEmitter.emit('callSyncFunction')// Needs await if I want to catch the error even though it is calling a sync function to work as expected.}catch(e){console.log(e)}// Unhandled Promise Rejection. Requires await before eventEmitter.emit('callSyncFunction') even though calling sync function to allow it to catch the error.
Right now I am using the in-built node eventEmitter for synchronous functions and this one for async functions. If this is fixed, I can simply use this emitter and not use the in-built one at all.
The text was updated successfully, but these errors were encountered:
Right now I am using the in-built node eventEmitter for synchronous functions and this one for async functions. If this is fixed, I can simply use this emitter and not use the in-built one at all.
The text was updated successfully, but these errors were encountered: