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

Use async/await for internal readAsync function. NFC #23120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Dec 10, 2024

Followup to #23104.

#if ASSERTIONS
assert(!binary || Buffer.isBuffer(ret));
#endif
return ret;
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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));
Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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

Copy link
Member

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.

@sbc100 sbc100 force-pushed the readAsync branch 3 times, most recently from 90b6983 to 8bf08af Compare December 10, 2024 23:09
@sbc100 sbc100 enabled auto-merge (squash) December 10, 2024 23:21
@@ -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));
Copy link
Member

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.

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.

2 participants