pub struct AndThen<A, B> { /* private fields */ }Expand description
Calls two services in sequence, passing the first response to the second.
Created by Service::and_then and crate::ServiceChain::and_then.
Both services use the same state and error types. The first service accepts
the input request, and the second service produces the final response.
If the first call fails, its error is returned without calling the second
service. Errors from the second call are also returned unchanged.
To pass both successful responses and errors to the next service, use
crate::ServiceChain::then instead.
§Readiness and lifecycle
Binding is forwarded to both children. Readiness succeeds only when both children are ready; a readiness error from either child is returned unchanged. Shutdown drives both children’s shutdown futures to completion.
Children share the enclosing readiness scope unless explicitly wrapped
with crate::ready(). Calls forward directly to each child without
another readiness check for raw services. Wrap a child when it needs an
independent readiness cache and a check at call time, especially when the
second child’s readiness can change while the first call is awaiting.
Cloning clones both children; any shared state or readiness depends on their clone implementations.
§Example
use ntex_service::{Service, fn_service};
let pipeline = fn_service(async |req: u32| Ok::<_, ()>(req + 1))
.and_then(fn_service(async |value: u32| Ok::<_, ()>(value.to_string())))
.pipeline(());
assert_eq!(pipeline.call(41).await?, "42");See the framework guide’s Service Pipelines chapter for composition and readiness semantics.