-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Use async/await for internal readAsync function. NFC #23120
base: main
Are you sure you want to change the base?
Conversation
#if ASSERTIONS | ||
assert(!binary || Buffer.isBuffer(ret)); | ||
#endif | ||
return ret; |
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.
The async keyword automatically makes the return value into a promise here.
setTimeout(() => resolve(readBinary(f))); | ||
}); | ||
}; | ||
readAsync = async (f) => readBinary(f); |
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.
The async keyword automatically makes the return value into a promise here.
@@ -9,18 +9,17 @@ readBinary = (filename) => { | |||
filename = isFileURI(filename) ? new URL(filename) : filename; | |||
var ret = fs.readFileSync(filename); | |||
#if ASSERTIONS | |||
assert(ret.buffer); | |||
assert(Buffer.isBuffer(ret)); |
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.
I think this is more accurately reflects what this assertion was trying to prove. i.e. that the returned value is a node Buffer
object.
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.
That sounds right, but I recall some differences between node versions... we do have coverage of multiple ones on CI though, so if it passes we should be ok I guess.
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.
I was trying to figure out what this assert could possibly be for... is it to detect older node versions that don't return a buffer? If so, shouldn't we just do that with the version check? Buffer.isBuffer
has been around forever so I certainly think it should be fine to use: https://nodejs.org/api/buffer.html#static-method-bufferisbufferobj
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.
Oh right, yeah, it was whether a Buffer was returned or not. Yeah, this lgtm.
90b6983
to
8bf08af
Compare
@@ -9,18 +9,17 @@ readBinary = (filename) => { | |||
filename = isFileURI(filename) ? new URL(filename) : filename; | |||
var ret = fs.readFileSync(filename); | |||
#if ASSERTIONS | |||
assert(ret.buffer); | |||
assert(Buffer.isBuffer(ret)); |
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.
That sounds right, but I recall some differences between node versions... we do have coverage of multiple ones on CI though, so if it passes we should be ok I guess.
Followup to #23104.