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

feat(net): getAvailablePort() #3890

Merged
merged 9 commits into from
Dec 4, 2023
Merged

feat(net): getAvailablePort() #3890

merged 9 commits into from
Dec 4, 2023

Conversation

harrysolovay
Copy link
Contributor

Closes #3279

@CLAassistant
Copy link

CLAassistant commented Dec 1, 2023

CLA assistant check
All committers have signed the CLA.

@kt3k
Copy link
Member

kt3k commented Dec 2, 2023

Please create a file for each API with corresponding file name, and re-export them from mod.ts (We follow that pattern in newer modules).

@kt3k
Copy link
Member

kt3k commented Dec 2, 2023

Also please write some test for each API

net/port.ts Outdated Show resolved Hide resolved
net/port.ts Outdated
* @param ms the duration of the intervals between re-checking readiness
* @throws if the inner `Deno.connect` call throws a non `Deno.errors.ConnectionRefused` error.
*/
export async function ready(port: number, ms = 500): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make the second argument option object. We probably would like to add more options in the future (e.g. signal: AbortSignal, timeout: number. etc)

ref: https://docs.deno.com/runtime/manual/references/contributing/style_guide#exported-functions-max-2-args-put-the-rest-into-an-options-object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got rid of this function altogether. I think iuioiua's comment about using retry is correct (even moreso in light of mention of abort behavior / ie. would the function throw?).

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

LGTM once that assert() in the test is addressed.

Deno.test("getAvailablePort() gets an available port", async () => {
const port = getAvailablePort();

assert(port > 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems redundant.

net/get_available_port.ts Show resolved Hide resolved
@iuioiua iuioiua changed the title feat: net port utils feat(net): getAvailablePort() Dec 3, 2023
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

@harrysolovay Thanks for your contribution!

@kt3k kt3k merged commit 1dc2369 into denoland:main Dec 4, 2023
12 checks passed
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.

suggestion: getAvailablePort()
4 participants