Skip to main content

ready

Function ready 

Source
pub fn ready<S, St, Req>(
    service: impl IntoService<S, St, Req>,
) -> ServiceChain<Ready<S>, St, Req>
where S: Service<St, Req>,
Expand description

Wraps a service with independent, notification-invalidated readiness.

Unlike raw children of combinators, the wrapped service retains its own successful readiness and checks it on each call. Changes to a sibling do not discard this cache. The service must subscribe to all readiness-change sources in Service::bind and notify when readiness changes.

Calls do not consume readiness. Cloning the wrapper creates a fresh cache; an std::rc::Rc around the wrapper shares the service and its cache.

use ntex_service::{Service, fn_service, ready};

let pipeline = ready(fn_service(async |req: u8| Ok::<_, ()>(req)))
    .and_then(ready(fn_service(async |req: u8| Ok::<_, ()>(req + 1))))
    .pipeline(());
assert_eq!(pipeline.call(1).await?, 2);