Merge pull request #1698 from ealmloff/fix-server-function-early-disconnect

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2023-12-07 09:28:54 -08:00
commit 424926a8db
1 file changed
+9 -9
+9 -9
View File
@@ -89,9 +89,9 @@ impl Service for ServerFnHandler {
let parts = Arc::new(RwLock::new(parts)); let parts = Arc::new(RwLock::new(parts));
// Because the future returned by `server_fn_handler` is `Send`, and the future returned by this function must be send, we need to spawn a new runtime // Because the future returned by `server_fn_handler` is `Send`, and the future returned by this function must be send, we need to spawn a new runtime
let (resp_tx, resp_rx) = tokio::sync::oneshot::channel();
let pool = get_local_pool(); let pool = get_local_pool();
pool.spawn_pinned({ let result = pool
.spawn_pinned({
let function = function.clone(); let function = function.clone();
let mut server_context = server_context.clone(); let mut server_context = server_context.clone();
server_context.parts = parts; server_context.parts = parts;
@@ -101,14 +101,14 @@ impl Service for ServerFnHandler {
Encoding::GetJSON | Encoding::GetCBOR => &query, Encoding::GetJSON | Encoding::GetCBOR => &query,
}; };
let server_function_future = function.call((), data); let server_function_future = function.call((), data);
let server_function_future = let server_function_future = ProvideServerContext::new(
ProvideServerContext::new(server_function_future, server_context.clone()); server_function_future,
let resp = server_function_future.await; server_context.clone(),
);
resp_tx.send(resp).unwrap(); server_function_future.await
} }
}); })
let result = resp_rx.await.unwrap(); .await?;
let mut res = http::Response::builder(); let mut res = http::Response::builder();
// Set the headers from the server context // Set the headers from the server context