Skip to content

[endpoint] Return a promise that resolves/reject on listen(). #296

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

Merged
merged 2 commits into from
Mar 26, 2024

Conversation

igalshilman
Copy link
Contributor

This PR makes sure that the returned promise from endpoint.listen() resolves whenever the server is successfully listening on the provided port. Otherwise reject with the first error.

This commit makes sure that the returned promise from endpoint.listen()
resolves whenever the server is successfully listening on the provided
port. Otherwise reject with the first error.
@igalshilman igalshilman requested a review from nikrooz March 25, 2024 19:42
});
server.listen(actualPort, () => {
if (!failed) {
resolve();
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about resolving this promise with at least the current port? This is especially useful if you start listening on 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, good idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

just out of curiosity we don't want to give the user access to the server, basically resolving the promise with the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can, but it seems like leaking a concrete implementation, will be hard to use anything else if we do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikrooz would you find it more useful to have access to the h2 server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks everyone for the suggestions, I'll merge this meanwhile. We can iterate with a progressively more advanced options later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily, I just mentioned it in case we want to be aligned with nodes api.
https://nodejs.org/api/net.html#serverlistenport-host-backlog-callback

});
server.listen(actualPort, () => {
if (!failed) {
resolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

just out of curiosity we don't want to give the user access to the server, basically resolving the promise with the server.

@igalshilman igalshilman merged commit 6ef2435 into restatedev:main Mar 26, 2024
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.

3 participants