GithubHelp home page GithubHelp logo

Comments (5)

mcollina avatar mcollina commented on June 26, 2024 1

What is the assumed behavior for writeToStream()? Do we assume that whenever we call it, the highwatermark will be hit and subsequently the drain will be called? Or is that a false assumption being made by the aedes code?

Either drain or error will be emitted if writeToStream return false. There is no need to wait if it returns true.

What is the best way to check if the call succeeded to write the data to the stream or if it failed?

You don't want to wait for a confirmation that data is written to the stream. It has no real meaning of being actually sent on the wire, just that it has been received by the underlining layer. In fact, sending the data could fail even if the callback is invoked successfully.

The way Aedes does it is correct to achieve maximum throughput on a socket.

from mqtt-packet.

vishnureddy17 avatar vishnureddy17 commented on June 26, 2024

Thanks for the clarification @mcollina.

Follow-up question: What is the rationale behind the design of emitting errors on the passed-in stream outside of the internal stream context? My naive inclination would be that error should only be emitted internally in the stream context and not from the outside.

For context, I've been discussing with @YoDaMa offline.

from mqtt-packet.

mcollina avatar mcollina commented on June 26, 2024

Follow-up question: What is the rationale behind the design of emitting errors on the passed-in stream outside of the internal stream context? My naive inclination would be that error should only be emitted internally in the stream context and not from the outside.

I don't understand the question. Some of the design of Node.js stream does not have a clear rationale, it just happened 🤦‍♂️😅.

from mqtt-packet.

vishnureddy17 avatar vishnureddy17 commented on June 26, 2024

Sorry my question wasn't clear. In mqtt-packet, if there is an error then stream.emit('error') is called. I would think it is bad practice to call emit('error') on the stream instance because it is not part of the public API of streams and is an internal thing. What is the reason for mqtt-packet to do this?

Example:

stream.emit('error', new Error('Invalid protocol version'))

from mqtt-packet.

mcollina avatar mcollina commented on June 26, 2024

Oh! I forgot we were doing that in this module. This problem was fixed long ago in Node.js. We should be calling stream.destroy(err) instead.

Would you like to send a PR?

from mqtt-packet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.