Rocket icon indicating copy to clipboard operation
Rocket copied to clipboard

Responder does not use Future, contrary to the documentation

Open emembrives opened this issue 3 years ago • 2 comments

Description

In core/lib/src/response/responder.rs, line 109, it is written that

/// A `Responder` returns a `Future` whose output type is a `Result<Response,
/// Status>`.

which would be a very useful feature.

However, the code of the Responder trait is not async nor uses a Future, contrary to what the documentation says:

    fn respond_to(self, request: &'r Request<'_>) -> response::Result<'o>;

It would be great to have this feature available.

emembrives avatar Jul 21 '22 21:07 emembrives

From my understanding, the doc comment is wrong, responders aren't meant to be async. It's the Handler's job to do any async calculation prior to returning the Responder. In can't think of a situation where respond_to being sync would make anything harder. However, you could still respond with (async) streams depending on what you're trying to do exactly. This can be seen as an "async response" in a way...

edgarogh avatar Aug 29 '22 11:08 edgarogh

@edgarogh's response is exactly right. This is a doc bug. The string should be updated to reflect what @edgarogh has commented.

SergioBenitez avatar Aug 29 '22 16:08 SergioBenitez