bakkerthehacker / bramqp

A radical, raw, robust, remarkable, rapid AMQP library for node.js
MIT License
162 stars 20 forks source link

any plans to rewrite bramqp in async/await? #56

Open Dmitry-N-Medvedev opened 7 years ago

Dmitry-N-Medvedev commented 7 years ago

...this would be very handy for modern NodeJS

bakkerthehacker commented 7 years ago

I dont have any immediate plans to update bramqp to use more modern javascript features, but it is something I have thought about. Updating the callbacks to something more suitable does make sense, but the library does function as is. Another consideration is which version of node is supported. Currently, bramqp works with node all the way back to version 0.10

Dmitry-N-Medvedev commented 7 years ago

If I am not mistaken, node since v. 7.0.0 does natively support async/await

bakkerthehacker commented 5 years ago

With the release of many of the important async / await features in node 12, I am happy to refactor bramqp to use promises.

My plan is to have the interface look something like:

handle.server.channel(num)[class][method](), async generator that emits methods from the server

handle.client.channel(num)[class][method](...args), async, returns promise that resolves on server response

bakkerthehacker commented 4 years ago

Just wanted to give an update. I have built out some async prototypes and looked into a few strategies here.

The branches generator-dev and async-dev contain some of my initial prototyping with various javascript async features. However, in my building, especially when trying to use generators to nicely encapsulate parsing, i ran into limitations in the vanilla js generators.

In addition to vanilla features, node also provides streams. While this interface is a bit different, it seems more suitable for bramqp internals as it contains piping and flow control. My work on converting bramqp to use duplex streams is more complete than the other two branches but it is not entirely finished. It available in the stream-dev branch. While some of the internals may change a bit still, this new tutorial is what I am looking to implement and is a good reference for the new interface. (the 1st has been updated, some of the others still need to be)

With this new interface, each level of amqp is a stream (handle, channel, class, method). Data can be sent to the server by writing to the stream using the appropriate interface. Methods may also be called and will send the data to the stream. These streams also produce data when it is received from the server.

Dmitry-N-Medvedev commented 4 years ago

just came across this article regarding node streams: https://github.com/nodejs/readable-stream

hope this helps :)

bakkerthehacker commented 4 years ago

Thanks for the insight but maybe I don't see the same issues with the stock streams as that author does. The blog post is from 2014 and is mainly raising issue with changing interfaces from streams in node 0.8-0.10. These node versions are quite old so I am fine relying on stock streams3 from node 12 onward rather than adding more to the npm install.