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

Prefer for..of loops to forEach for perf #32

Merged
merged 6 commits into from
Jan 22, 2025
Merged

Prefer for..of loops to forEach for perf #32

merged 6 commits into from
Jan 22, 2025

Conversation

KurtPreston
Copy link
Collaborator

No description provided.

const execution = fn(payload);
// Emit errors if fn returns promise that rejects
(execution as Promise<any>)?.catch?.((e) => {
if(event === Lifecycle.error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I don't like about this PR is the redundancy here. Lines 709-717 are the same as 724-734.

I thought about pulling this error logic into a function to eliminate the redundancy, but I wanted to avoid the overhead of creating a closure when we hit the happy path.

@@ -798,6 +798,22 @@ describe('Strongbus.Bus', () => {
});
});

it('raises "error" when the listener returns a promise that rejects', async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spec is old behavior, but I didn't see it previous captured by a spec.

const error = new Error('Error in callback');
bus.on('bar', () => {
throw error;
describe('error events', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these new specs are just capturing existing behavior. They all pass against the master branch.

@epferrari epferrari merged commit 479a71f into master Jan 22, 2025
@epferrari epferrari deleted the optimize-iter branch January 22, 2025 19:53
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.

2 participants