Implement Server::add_request_handler in terms of ::add_message_handler

This commit is contained in:
Antonio Scandurra 2022-02-14 09:31:31 +01:00
parent 1aff42302c
commit 68917c78be

View File

@ -121,12 +121,9 @@ impl Server {
Fut: 'static + Send + Future<Output = tide::Result<M::Response>>,
M: RequestMessage,
{
let prev_handler = self.handlers.insert(
TypeId::of::<M>(),
Box::new(move |server, envelope| {
let envelope = envelope.into_any().downcast::<TypedEnvelope<M>>().unwrap();
self.add_message_handler(move |server, envelope| {
let receipt = envelope.receipt();
let response = (handler)(server.clone(), *envelope);
let response = (handler)(server.clone(), envelope);
async move {
match response.await {
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(