Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(breaking): return errors instead of throwing #120

Closed
wants to merge 9 commits into from

Conversation

KATT
Copy link

@KATT KATT commented Nov 29, 2024

Closes #51

Quick PR to showcase #51 (comment)

Hey, I just found this old thread while thinking of adopting emittery.

Would it make sense for emit() to never throw and instead return Promise<null | [unknown, ...unknown]>?

import Emittery from 'emittery';

const emitter = new Emittery<{
  '🦄': string;
}>();

emitter.on('🦄', () => {
  // works
});

emitter.on('🦄', () => {
  throw new Error('💣');
});

const result = await emitter.emit('🦄', 'a');

if (result) {
  // result would be [Error('💣')]
  console.error('Errors', result);
} else {
  console.log('all OK!');
}

@KATT
Copy link
Author

KATT commented Nov 29, 2024

An alternative would be to have some sort of global captureUncaughtExceptions setting or whatnot.

Either way, if we'd do this there'd need to be a global handler where you can log failures etc

@KATT
Copy link
Author

KATT commented Dec 6, 2024

We decided not to use awaitable event emitters so I will close this, feel free to take the code if it's of interest

@KATT KATT closed this Dec 6, 2024
@KATT KATT deleted the issues/51-emit-result branch December 6, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make emit() wait for all listeners to settle
1 participant