Struct interlink::service::ServiceContext
source · pub struct ServiceContext<S: Service> { /* private fields */ }
Expand description
Backing context for a service which handles storing the reciever for messaging and the original link for spawning copies
Implementations§
source§impl<S: Service> ServiceContext<S>
impl<S: Service> ServiceContext<S>
sourcepub fn attach_sink<Si, I>(&self, sink: Si) -> SinkLink<I>where
S: ErrorHandler<Si::Error>,
Si: Sink<I> + Send + Unpin + 'static,
Si::Error: Send + 'static,
I: Send + 'static,
pub fn attach_sink<Si, I>(&self, sink: Si) -> SinkLink<I>where S: ErrorHandler<Si::Error>, Si: Sink<I> + Send + Unpin + 'static, Si::Error: Send + 'static, I: Send + 'static,
Attaches a sink to this service and provides a link to the service so that it can be used to write messages
sink
The sink to attach
source§impl<S> ServiceContext<S>where
S: Service,
impl<S> ServiceContext<S>where S: Service,
sourcepub fn attach_stream<St>(&self, stream: St, stop: bool)where
S: StreamHandler<St::Item>,
St: Stream + Send + Unpin + 'static,
St::Item: Send + 'static,
pub fn attach_stream<St>(&self, stream: St, stop: bool)where S: StreamHandler<St::Item>, St: Stream + Send + Unpin + 'static, St::Item: Send + 'static,
Attaches a streaming reciever to the service context
implement the StreamHandler trait on your service with the item as the Item type of the provided stream in order to handle accepting items from the stream
stream
The stream to accept from
stop
Whether to stop the main service when this stream service ends
source§impl<S> ServiceContext<S>where
S: Service,
impl<S> ServiceContext<S>where S: Service,
sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Stop the context directly by closing the reciever the reciever will drain any existing messages until there are none remaining
Returns a reference to the shared link used by this context for creating new links. You can use this to access the service link without creating a clone of it