Replace callback-based requests/messages with streams
This commit is contained in:
parent
8b66e0aa7e
commit
8112efd522
8 changed files with 306 additions and 137 deletions
|
@ -1,8 +1,5 @@
|
|||
use futures::Future;
|
||||
use gpui::MutableAppContext;
|
||||
use rpc_client::RpcClient;
|
||||
use std::sync::Arc;
|
||||
use zed_rpc::proto::RequestMessage;
|
||||
|
||||
pub mod assets;
|
||||
pub mod editor;
|
||||
|
@ -27,27 +24,6 @@ pub struct AppState {
|
|||
pub rpc_client: Arc<RpcClient>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub async fn on_rpc_request<Req, F, Fut>(
|
||||
&self,
|
||||
cx: &mut MutableAppContext,
|
||||
handler: F,
|
||||
) where
|
||||
Req: RequestMessage,
|
||||
F: 'static + Send + Sync + Fn(Req, &AppState, &mut MutableAppContext) -> Fut,
|
||||
Fut: 'static + Send + Sync + Future<Output = Req::Response>,
|
||||
{
|
||||
let app_state = self.clone();
|
||||
let cx = cx.to_background();
|
||||
app_state
|
||||
.rpc_client
|
||||
.on_request(move |req| cx.update(|cx| async move {
|
||||
handler(req, &app_state, cx)
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(cx: &mut gpui::MutableAppContext) {
|
||||
cx.add_global_action("app:quit", quit);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue