-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Explore Promises in addition to callbacks #991
Comments
A problem with promise based apis is that it is not compatible with the optional callback / error event style approach we've adopted; // Current api
let port = new SerialPort('/bad-port', {autoOpen: false});
port.on('open', () => console.log('yay the port is open!'))
port.on('error', () => console.log('boo we had an error!'))
port.open(); // no callback
// boo we had an error!
port.open(function(err) { if (err) { console.log("I'm dealing with this error") }});
// I'm dealing with this error In node 6x+ unhandled promises throw globally, in all nodes unhandled error events throw globally. We're still going to support 4x. This might not be something we need to worry about. So if also always return a promise or only return a promise when not given a callback, and we don't handle it's rejection some nodes will throw. And if we don't provide a callback and don't handle the All our functions throw when given bad arguments, there seems to be a consensus around rejecting promises instead. I think this all means that we'd have to switch wholesale to promises instead of callbacks. |
There is an alternative approach which we can take, and that is to do what nodejs core is eventually going to do. Providing functionAsync equivalents that return promises. That's probably the way to go. |
This isn't on the roadmap for now. |
Hi @reconbot , any chance of revisiting this, or accepting PR's for work on this? Currently we are forced to use Bluebird to promisify the When I rewrote the Node API for Sendgrid, we also introduced promise support while maintaining callbacks for backwards compatibility. I see the issue with not passing a callback and not handling rejected promises, which could trip up apps using callbacks. However, given the speed at which you are releasing major versions with other breaking changes, it's conceivable that a new major version is released that either always expects promises/async to be used. Alternatively, have you considered a flag that enabled promises globally (or during instantiation of the const port = new SerialPort(port, {
baudRate,
autoOpen: false,
usePromises: true,
}); This could even be the default setting, with optional Thoughts? |
The next major version is unfortunate. It fixes some major windows performance issues and changes our binary distribution system. Doing the bump seemed worth it even though there's only potential behavior changes. As for promises. I started using them for the bindings but one of the goals was to match the node stream api as close as possible. In fact most of the "magic" is in the bindings. I'm doing an exploration of other kinds of streams (whatwg/streams, most) and async iterators. But I doubt we'd switch this project to any of them, but instead share the bindings with other packages. (and probably split them into their own package) So async methods for node serialport? The convention doesn't exist for node streams but we snuck it into
It seems that node core is moving towards the PS I'd love to make a non node-streams version of serialport. And I love |
Thanks for the detailed comments! Since I use the I wouldn't mind if the API is split between callback and non-callback functions, but I think the naming would be misleading. E.g. So I would prefer the approach where
Amen! |
I'm wrong on the |
I see, interesting read. I guess their main concern is maintaining backwards compatibility with callbacks. It also looks like the discussion ended about a year ago. |
For me it's not backwards compatibility it's principal of least surprise. I'd like node serialport to work like everything else does. |
Someone needs to be the trend setter ;) |
Everything in NodeJs is moving to promises, so I think that a new major release non-backward compatible is acceptable. |
I'm 💯 of a different mind these days about this. We still support node 6 which doesn't have async functions but I'd be willing to transpile to ignore that fact. |
Nodejs 6 has a scheduled eol date at April 19. Yes, with babel the "compilation" is very easy. If you need beta testers when you want to update the code with promises/asyncawait feel free to ask, I'm happy to help you. I'm using this module in a project wrapping every api that I'm using in promises. |
The steam object has to keep working like a stream, but we could take a few
of our custom functions and have them return promises.
However I think we need an ansyc Iterator interface. This new interface
could do anything it wants.
…On Sat, Sep 15, 2018, 6:23 AM Stefano Cappa ***@***.***> wrote:
Nodejs 6 has a scheduled eol date at April 19.
So, it could be the right moment to switch to node 8 updating the code.
Yes, with babel the "compilation" is very easy.
If you need beta testers when you want to update the code with promises
feel free to ask, I'm happy to help you. I'm using this module in a project
wrapping every api that I'm using in promises.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#991 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABlbhEY1KSFB3EZhhkRx1XcGpj7G234ks5ubNUtgaJpZM4Ko7M3>
.
|
Yes, I suppose that it's impossible to promisify a stream |
Alright, what do you all think about this? #1850 |
Usurps #261
We'll be dropping older nodes around version 6, we currently polyfill promises for version 4, so we got them to use.
We'd need tests along with any PR
The text was updated successfully, but these errors were encountered: