-
Notifications
You must be signed in to change notification settings - Fork 84
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
Replacing callbacks to improve readability #483
Comments
I want to do this if it gets approved. I am new to contributing to open sources so I'll need some support. |
Theoretically speaking, there should be no breaking changes. This is just removing complexity before it gets out of hand, as I have seen in past projects. Of course, this is just a suggestion, as it has absolutely no impact on the SDK features. (I'll help with this one day, I promise x) ) I'll check the code to be sure, and suggest a PR. @nav-D, once I get the PR ready, would you help me getting it right ? |
/assign |
@SoTrx Sure I’d love to help out. |
@XavierGeerinck - is this still a good first issue for contributors? Looks like there was never a PR opened. |
Adding @shubham1172 I would say it could be, but it's a bit stale so we would prefer other issues first |
Thanks a lot for this PR! We had a discussion around it and are going to put it on hold. The reason for this is since the Node.JS ecosystem is becoming more fragmented daily with new runtimes such as Deno, Bun, .... with Bun having a good change of taking it over. Introducing this PR would require us to scope the input of supporting additional runtimes as some are Node supported only while others don't carry this requirement. |
That's a very good point ! |
Node's promisify is a very simple wrapper and could easily be inlined, something like: const promisify = fn => (...args) => new Promise((resolve, reject) => {
fn(...args, (error, value) => {
if (error) {
reject(error);
} else {
resolve(value);
}
});
});
Yikes. I think you're wildly over-estimating the fragmentation of Node. (Have we learned nothing from yarn?) If Bun intends to be a drop-in replacement for NodeJS then by all means let it drop-in, but don't let it block useful enhancements like this. |
Describe the proposal
In it's current state, the code uses two main ways to handle asynchronous operations.
The HTTP implementation uses promises, and the GRPC implementation uses (or more likely "have to use") callbacks.
Using callbacks has always been a pain in JS, as we have to deal with both synchronous and asynchronous errors, leading to some "mandatory boilerplate".
For example, in sidecar.ts
The purpose of this issue would be to replace most of the GRPC client callbacks with promises.
Although there is no performance benefit to doing this (nor any performance hit), it will greatly improve the readability of the code, especially as more complex features are added to the SDK (i.e Workflows), in which we may have to deal with nested callbacks.
To achieve this, we could use the promisify function (included in Node 8+).
On the same example, it would look something like this.
I can see two ways in which this could be used. We could use the promisify function each time the GRPC client is used, which is simple.
Or we could wrap the whole GRPC client class in an adapter class, that "promisifies" all of the client's methods, which would be more DRY, but add a bit of extra maintenance.
What do you think ?
The text was updated successfully, but these errors were encountered: