Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/rmcp/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ pub struct RunningService<R: ServiceRole, S: Service<R>> {
service: Arc<S>,
peer: Peer<R>,
handle: tokio::task::JoinHandle<QuitReason>,
/// cancellation token with drop guard
cancellation_token: CancellationToken,
dg: DropGuard,
}
impl<R: ServiceRole, S: Service<R>> Deref for RunningService<R, S> {
type Target = Peer<R>;

fn deref(&self) -> &Self::Target {
self.peer()
&self.peer
}
}

Expand All @@ -444,6 +444,11 @@ impl<R: ServiceRole, S: Service<R>> RunningService<R, S> {
pub fn service(&self) -> &S {
self.service.as_ref()
}
#[inline]
pub fn cancellation_token(&self) -> RunningServiceCancellationToken {
RunningServiceCancellationToken(self.cancellation_token.clone())
}
#[inline]
pub async fn waiting(self) -> Result<QuitReason, tokio::task::JoinError> {
self.handle.await
}
Expand All @@ -454,6 +459,15 @@ impl<R: ServiceRole, S: Service<R>> RunningService<R, S> {
}
}

// use a wrapper type so we can tweak the implementation if needed
pub struct RunningServiceCancellationToken(CancellationToken);

impl RunningServiceCancellationToken {
pub fn cancel(self) {
self.0.cancel();
}
}

#[derive(Debug)]
pub enum QuitReason {
Cancelled,
Expand Down Expand Up @@ -801,6 +815,7 @@ where
service,
peer: peer_return,
handle,
cancellation_token: ct.clone(),
dg: ct.drop_guard(),
}
}
Loading