nodegit icon indicating copy to clipboard operation
nodegit copied to clipboard

[refactor] use async/await syntax?

Open samuela opened this issue 2 years ago • 4 comments

As I dig through the source, I'm noticing that there's a lot of messy manual Promise chaining, eg. https://github.com/nodegit/nodegit/blob/master/generate/scripts/generateNativeCode.js#L121-L171. Is there a reason not to use async/await syntax? I'd be happy to submit some PRs if maintainers would be interested.

samuela avatar Oct 17 '21 03:10 samuela

For some context async/await syntax has been supported in node.js since v7.6.0 which is from 2017, so we wouldn't be dropping support for barely anyone AFAICT.

samuela avatar Oct 17 '21 05:10 samuela

I have completed a translation from .then-ing to async/await for the entire lib/ and lifecycleScripts/ directories. Commits are linked above. There are only a handful of .thens left in places where they actually appear to be the cleanest solution. Otherwise everything has been refactored to use async/await for clarity.

Everything builds and passes the entire test suite. Throughout the process I also upgraded the test runner from istanbul to nyc. It turns out that istanbul has been deprecated, and nyc is the recommended solution now. See https://github.com/samuela/nodegit/commit/63c801c48f48aa5587e60b99b90211039e602ad5 for more info.

Using async/await syntax also required upgrading jshint, and updating the configuration to use the "esversion": 9 config option instead of esnext which has been deprecated. See https://github.com/samuela/nodegit/commit/e09963961185d76a4d7e088df4a8d489c35e0289 for more info.

I'd be happy to contribute all these changes upstream if they are of interest to maintainers. Let me know! (cc @implausible @ianhattendorf others?)

samuela avatar Oct 18 '21 01:10 samuela

Could this be considered?

Vadorequest avatar Jun 12 '22 14:06 Vadorequest

Why is this being ignored? Is there some good reason to avoid migrating the project to the modern async/await syntax?

jeremyj563 avatar Dec 13 '23 21:12 jeremyj563