zeromq / zeromq.js

:zap: Node.js bindings to the ØMQ library
http://zeromq.github.io/zeromq.js/
MIT License
1.45k stars 209 forks source link

Support events on the Socket #463

Open overflowz opened 3 years ago

overflowz commented 3 years ago

Is your feature request related to a problem? Please describe. This is related to the 6.x version. Async generators are great, but I personally prefer handling messages with events (available in v5). The reason being the architecture of most of my projects. I also would like to break sometimes (I don't want await to hang forever until a message is available).

Describe the solution you'd like I'd like that the Socket to extend the EventEmitter class (or Observable) so I can instead listen to message events rather than forced to use async iterators only.

n-riesco commented 3 years ago

There is a compatibility layer: see the documentation here.

As an example, see here how I transitioned jmp to v6. The main difficulty I found was that zmq.Socket is now defined as an ES6 class, which forced my refactoring jmp.Socket as an ES6 class too. Also, don't forget to add deasync to your dependencies, if your project uses Socket#bind.

overflowz commented 3 years ago

Thanks for the reply! I tried the compat version, but it isn't what I'm looking for(?). The types are well defined for socket options in v6, but when trying the v5-compat -- types aren't that well defined (and I'm not sure why. Maybe there's a reason for it?).

So my question is: is the v5-compat actual version 5 of the zeromq, or is it just a v6 with v5 compatibility? how it will be maintained / will get issues fixed if there are two versions of them (i.e., would adding a new feature to v6 also be reflected in v5-compat)? and how long will that last, would it drop support for v5-compat eventually?

While it is recommended to use v5-compat instead, we'll eventually have to switch to v6 (or any next versions in the future), so I'm guessing new features should land only in v6 while leaving v5 alone (except for bug fixes of course).

n-riesco commented 3 years ago

I only have an answer for one of your questions:

So my question is: is the v5-compat actual version 5 of the zeromq, or is it just a v6 with v5 compatibility?

The answer is yes, the compatibility layer is built on top of zeromq@6; see:

https://github.com/zeromq/zeromq.js/blob/ce7b4a7035db68f242c7b241928e108fa7faa5a5/src/compat.ts#L30-L31


And for the reason why is hard to answer the other questions, see #442