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

Allow awaiting on server handles #550

Merged
merged 2 commits into from
Nov 8, 2021
Merged

Conversation

slumber
Copy link
Contributor

@slumber slumber commented Nov 4, 2021

  • Rename both HttpStopHandle and WsStopHandle to HttpServerHandle and WsServerHandle respectively
  • Implement Future for both allowing to do
let (addr, handle) = server.start(rpc).unwrap();
handle.await

to run the server forever.

The interfaces for HTTP and WS are slightly different in the sense that the latter handle can be cloned. This can be easily implemented via channels for HTTP but that's a subject for different PR and was not introduced here.

Resolves #547

stop_sender: mpsc::Sender<()>,
stop_handle: Option<tokio::task::JoinHandle<()>>,
pub(crate) handle: Option<tokio::task::JoinHandle<()>>,
Copy link
Member

@niklasad1 niklasad1 Nov 4, 2021

Choose a reason for hiding this comment

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

Is pub(crate) only needed for tests or why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used for tests

http-server/src/tests.rs Outdated Show resolved Hide resolved
server_handle.with_timeout(TIMEOUT).await.unwrap_err();

let (_addr, server_handle) = server().await;
server_handle.handle.as_ref().unwrap().abort();
Copy link
Member

Choose a reason for hiding this comment

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

ok, you did this instead of stop because it moves the JoinHandle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stop is a little bit different, here we want to emulate the actual server behavior -- if a task is cancelled or panics, the future handle resolves too.

ws-server/src/tests.rs Outdated Show resolved Hide resolved
Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

great, I like it

some minor questions to answered :)

Copy link
Contributor

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

Solid work!

@dvdplm dvdplm merged commit afcf411 into master Nov 8, 2021
@dvdplm dvdplm deleted the slumber-server-handle-fut-impl branch November 8, 2021 15:57
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.

Feature request: expose an access to http server handle
4 participants