mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 09:48:05 +03:00
rust/srserver: Simplify call to block on a server from async fn
Summary: The ffi call we use for launching a thrift server is a blocking call: [`thrift_server_serve`](diffusion/FBS/browse/master/fbcode/common/rust/srserver/src/RustThriftServer.cpp;4dc16e1ee0878536fa1fede8913e104ab998a270$366). That means calling it directly from an async fn is bad because it would block the executor and prevent any other task from making progress. To work around that, callers need to know that they must only call this off of their task's thread, such as on a threadpool. This diff moves the use of threadpool into the srserver crate, exposing `serve` instead as a simple async fn. **Before:** ``` future::poll_fn(move |_| tokio_threadpool::blocking(|| thrift.serve())).await??; ``` **After:** ``` thrift.serve().await?; ``` We keep the old blocking behavior under the new name `serve_blocking()`. This is needed for the Actix use case such as in Mononoke's apiserver, where Actix takes care of juggling threads itself and we don't need to bring our own threadpool. Reviewed By: Imxset21 Differential Revision: D16684766 fbshipit-source-id: bca2502b4eba8875569ed6c277f5606a6e2cefa0
This commit is contained in:
parent
6e5547492f
commit
24bcc078f1
@ -25,7 +25,7 @@ impl ThriftDispatcher {
|
||||
let mut thrift = thrift(self);
|
||||
|
||||
thrift
|
||||
.serve()
|
||||
.serve_blocking()
|
||||
.map_err(|e| eprintln!("Failed to start serve(): {}", e))
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user