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

Unclear documentation on how to remove EventListeners after adding #2476

Open
pulcomo opened this issue Apr 4, 2022 · 1 comment
Open

Unclear documentation on how to remove EventListeners after adding #2476

pulcomo opened this issue Apr 4, 2022 · 1 comment

Comments

@pulcomo
Copy link

pulcomo commented Apr 4, 2022

I am trying to implement a nodejs server application that reads data from a connected device over a USB port. The communication is based on UART and the protocol swaps from strings to bytes being sent.

More specifically, I need to send a read command, which will return a string of the length of the file (e.g. 25600). After this, my server application sends an acknowledgment and 1000 bytes will be received, I send ack and another 1000 bytes are received and this goes on until the last message, which in this example will return 600 bytes.

For this protocol, I implemented a new parser (1000 bytes, length % 1000 bytes and newline) for every new type of communication I expect and remove the old ones (with port.removeAllListeners("data"))

After a couple of files, I receive the MaxListenersExceededWarning. I know I can increase this, but I would feel more comfortable to just remove the listeners.

In the documentation, I cannot find how to remove listeners. Am I doing something wrong or is this just missing from the documentation?

@glenn-kroeze
Copy link

In the end, the SerialPort class class just extends the EventEmitter class. This means that removing an event listener is just as easy as adding an event listener; just call the off method in the same way you called the on method. Make sure whatever you passed into the on method references the same function as what you pass into the off method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants