mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Implement Server::add_request_handler in terms of ::add_message_handler
This commit is contained in:
parent
1aff42302c
commit
68917c78be
@ -121,12 +121,9 @@ impl Server {
|
|||||||
Fut: 'static + Send + Future<Output = tide::Result<M::Response>>,
|
Fut: 'static + Send + Future<Output = tide::Result<M::Response>>,
|
||||||
M: RequestMessage,
|
M: RequestMessage,
|
||||||
{
|
{
|
||||||
let prev_handler = self.handlers.insert(
|
self.add_message_handler(move |server, envelope| {
|
||||||
TypeId::of::<M>(),
|
|
||||||
Box::new(move |server, envelope| {
|
|
||||||
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
|
|
||||||
let receipt = envelope.receipt();
|
let receipt = envelope.receipt();
|
||||||
let response = (handler)(server.clone(), *envelope);
|
let response = (handler)(server.clone(), envelope);
|
||||||
async move {
|
async move {
|
||||||
match response.await {
|
match response.await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@ -144,13 +141,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.boxed()
|
})
|
||||||
}),
|
|
||||||
);
|
|
||||||
if prev_handler.is_some() {
|
|
||||||
panic!("registered a handler for the same message twice");
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_connection(
|
pub fn handle_connection(
|
||||||
|
Loading…
Reference in New Issue
Block a user