-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
@@ -511,8 +479,8 @@ function ensureWriteStreamSync(path, options) { | |||
}); | |||
}); | |||
|
|||
exports.access = accessAsync; | |||
exports.accessSync = accessSync; | |||
exports.access = Promise.promisify(fs.access); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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++).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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 ).