Skip to content

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Jun 16, 2024
1 parent cfbf44f commit de1d933
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl LocalServer {
self
}

/// Disable immediately shutdown the server upon handling the first request.
/// Shutdown the server when a signal is received from `receiver`.
pub fn with_shutdown_signal(mut self, receiver: Receiver<()>) -> Self {
self.shutdown_rx = Some(receiver);
self
Expand Down
35 changes: 18 additions & 17 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,24 @@ fn prepare_query_params(

/// Create the callback server that will receive the session token from the browser.
fn callback_server(result_sender: Sender<SessionDetails>) -> anyhow::Result<LocalServer> {
let handler =
move |State((res_sender, shutdown_sender)): State<(Sender<SessionDetails>, Sender<()>)>,
session: Json<SessionDetails>| async move {
info!("Received session token from the browser.");

res_sender
.send(session.0)
.await
.expect("qed; channel closed");

// send shutdown signal to the server ONLY after succesfully receiving and processing
// the session token.
shutdown_sender
.send(())
.await
.expect("failed to send shutdown signal.");
};
type HandlerState = State<(Sender<SessionDetails>, Sender<()>)>;

// Request handler for the /callback endpoint.
let handler = |state: HandlerState, json: Json<SessionDetails>| async move {
info!("Received session token from the browser.");

let State((res_sender, shutdown_sender)) = state;
let Json(session) = json;

res_sender.send(session).await.expect("qed; channel closed");

// send shutdown signal to the server ONLY after succesfully receiving and processing
// the session token.
shutdown_sender
.send(())
.await
.expect("failed to signal shutdown.");
};

let (shutdown_tx, shutdown_rx) = tokio::sync::mpsc::channel(1);

Expand Down

0 comments on commit de1d933

Please sign in to comment.