Skip to content
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

Useful fs.promises API & async / await #53

Merged
merged 7 commits into from Jan 14, 2020
Merged

Useful fs.promises API & async / await #53

merged 7 commits into from Jan 14, 2020

Conversation

segayuu
Copy link
Contributor

@segayuu segayuu commented Jan 5, 2020

If node version is 10 or later, fs.promises API and async / await, fs.Dirent are implemented.
While maintaining compatibility, the internal processing has been re-implemented entirely by using the fs.promises API via async / await etc. (As a result, the number of PR rows became large ).

@coveralls
Copy link

coveralls commented Jan 5, 2020

Coverage Status

Coverage increased (+0.8%) to 96.321% when pulling d48a89a on segayuu:useful-async-promises into 9fca381 on hexojs:master.

@@ -511,8 +479,8 @@ function ensureWriteStreamSync(path, options) {
});
});

exports.access = accessAsync;
exports.accessSync = accessSync;
exports.access = Promise.promisify(fs.access);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is Promise.promisify(fs.access) equivalent to fsPromises.access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two differences between the util.promisify() and Bluebird.promisify() functions.
One is whether the returned promise is a native promise or a bluebird.
The other is that the customization method such as this value and Promise.[[PromiseResult]] is different.
fs.access() has no this value and [[PromiseResult]] is undefined, so there is no difference other than returning Bluebird.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning util.promisify(fs.access) is equivalent to fsPromises.access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is almost no difference between fs.access() and fs.promises.access() at least in JavaScript implementation (only the line that calls the internal API is different, the implementation of that API is C++).

Copy link
Member

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@segayuu segayuu merged commit 336747f into hexojs:master Jan 14, 2020
@segayuu segayuu deleted the useful-async-promises branch January 14, 2020 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants