-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix event emitter leak warning #59
Conversation
src/telegramServer.ts
Outdated
this.off('EditedMessageText', handler); | ||
resolve(); | ||
}; | ||
this.on('EditedMessageText', handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can simply use once
onstead of on
- the we don't have to remove listener manually.
this.on('AddedUserMessage', () => resolve()); | ||
this.on('AddedUserCommand', () => resolve()); | ||
this.on('AddedUserCallbackQuery', () => resolve()); | ||
const messageHandler = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't look cool but I can't think of a better way too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be a little better to use once
in cases when we wait for one event.
Good point! |
src/telegramServer.ts
Outdated
this.on('AddedUserMessage', () => resolve()); | ||
this.on('AddedUserCommand', () => resolve()); | ||
this.on('AddedUserCallbackQuery', () => resolve()); | ||
this.once('AddedUserMessage', () => resolve()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything was right here in previous commit version. We wait for any signal and the turn off all emitters and resolve promise.
Now, one emitter will turn itself off but other two will stay and that's not what we expect :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, that's why you "can't think of a better way too"! =)) Indeed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Emitter is a great power which comes with great possibility of shooting your legs off :)
I have a really long integration test suite, that listens a lot on server edit messages. It was giving me these warnings: