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

Impossible to unregister event listener #21

Closed
Mi-La opened this issue Jan 20, 2020 · 1 comment · Fixed by #22
Closed

Impossible to unregister event listener #21

Mi-La opened this issue Jan 20, 2020 · 1 comment · Fixed by #22
Labels
bug Something isn't working

Comments

@Mi-La
Copy link

Mi-La commented Jan 20, 2020

See implementation in TcpSocket.js:

 on(event, callback) {
        switch (event) {
            case 'data':
                this._eventEmitter.addListener('data', (evt) => {
                    if (evt.id !== this._id) return;
                    const bufferTest = Buffer.from(evt.data, 'base64');
                    callback(bufferTest);
                });
                break;

Note that the listener function passed to the _eventEmitter is not the given callback, but a wrapper (evt => {.... Therefor it is impossible to use the off method to unregister the callback.

    off(event, callback) {
        this._eventEmitter.removeListener(event, callback);
    }
@Mi-La Mi-La added the bug Something isn't working label Jan 20, 2020
@Rapsssito Rapsssito self-assigned this Jan 20, 2020
@Rapsssito
Copy link
Owner

Rapsssito commented Jan 20, 2020

Thanks for pointing that out! I'll change the API so on( ) returns a listener with its own remove() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants