pub struct ServiceContext { /* private fields */ }Expand description
Shared runtime context provided to all managed services.
Implementations§
Source§impl ServiceContext
impl ServiceContext
Sourcepub fn new(name: impl Into<String>, protocol: Option<Protocol>) -> Self
pub fn new(name: impl Into<String>, protocol: Option<Protocol>) -> Self
Creates a new service context.
Sourcepub fn started_at(&self) -> DateTime<Utc>
pub fn started_at(&self) -> DateTime<Utc>
Returns when the context was created.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Returns the shared cancellation token.
Sourcepub fn child_token(&self) -> CancellationToken
pub fn child_token(&self) -> CancellationToken
Returns a child token for scoped tasks.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns whether cancellation has been requested.
Sourcepub fn subscribe(&self) -> Receiver<ServiceEvent>
pub fn subscribe(&self) -> Receiver<ServiceEvent>
Subscribes to service events.
Sourcepub fn emit(
&self,
event: ServiceEvent,
) -> Result<usize, SendError<ServiceEvent>>
pub fn emit( &self, event: ServiceEvent, ) -> Result<usize, SendError<ServiceEvent>>
Emits a service event.
Sourcepub fn track_task(&self, label: impl Into<String>, handle: &JoinHandle<()>)
pub fn track_task(&self, label: impl Into<String>, handle: &JoinHandle<()>)
Tracks an externally-spawned task under the context.
Sourcepub fn spawn_task<F>(
&self,
label: impl Into<String>,
future: F,
) -> JoinHandle<()>
pub fn spawn_task<F>( &self, label: impl Into<String>, future: F, ) -> JoinHandle<()>
Spawns and tracks a unit-returning background task.
Sourcepub fn tracked_tasks(&self) -> Vec<String>
pub fn tracked_tasks(&self) -> Vec<String>
Returns the tracked task labels.
Sourcepub fn abort_tracked_tasks(&self)
pub fn abort_tracked_tasks(&self)
Aborts all tracked tasks.
Trait Implementations§
Source§impl Clone for ServiceContext
impl Clone for ServiceContext
Source§fn clone(&self) -> ServiceContext
fn clone(&self) -> ServiceContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ServiceContext
impl !RefUnwindSafe for ServiceContext
impl Send for ServiceContext
impl Sync for ServiceContext
impl Unpin for ServiceContext
impl UnsafeUnpin for ServiceContext
impl !UnwindSafe for ServiceContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more