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(ext/ops) Add timeout parameter to Deno.Connect() #27113

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

DanieleAurilio
Copy link
Contributor

Related to #26819.
An optional timeout parameter has been added to the Deno.connect() interface. This parameter allows specifying a timeout (in milliseconds) within which the application must establish a connection. If the timeout is exceeded without successfully connecting, the operation is automatically aborted with an error. If the parameter is not provided, the default behavior remains unchanged (no timeout).
Currently, the timeout functionality is implemented only for TCP connections. Other connection types are not affected by this change.

Example usage:

try {
  const conn = await Deno.connect({
    hostname: "example.com",
    port: 5000,
    timeout: 5000, // 5 second timeout
  });

  console.log("Connection established successfully");  
  conn.close();
} catch (error) {
  if (error instanceof Deno.errors.TimedOut) {
    console.error("Connection timed out:", error.message);
  } else {
    console.error("Failed to connect:", error.message);
  }
}

If this solution is approved, the documentation will need to be updated to include details about the new timeout parameter.

@bartlomieju bartlomieju added this to the 2.2.0 milestone Nov 28, 2024
@DanieleAurilio
Copy link
Contributor Author

The commit 28ae134 add signal options to Deno.Connect() as discussed on issue #26819.

Found another issue #25265 related to timeout and signal on Deno.Connect.

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