pub struct TaskContext { /* private fields */ }Expand description
Handle passed to a running task operation, allowing it to surface
server-to-client requests (elicitation, sampling, roots) mid-task and
await the client’s tasks/update response.
Implementations§
Source§impl TaskContext
impl TaskContext
Sourcepub async fn request_input(
&self,
key: impl Into<String>,
request: InputRequest,
) -> Result<Value, TaskExit>
pub async fn request_input( &self, key: impl Into<String>, request: InputRequest, ) -> Result<Value, TaskExit>
Surface a server-to-client request under key and wait for the
client’s response delivered via tasks/update.
While at least one request is outstanding the task reports
input_required from tasks/get, with all outstanding requests in
inputRequests. Keys must be unique over the lifetime of the task;
reusing a key returns an error.
Sourcepub fn set_status_message(&self, message: impl Into<String>)
pub fn set_status_message(&self, message: impl Into<String>)
Update the task’s human-readable status message.
Sourcepub fn is_cancel_requested(&self) -> bool
pub fn is_cancel_requested(&self) -> bool
Returns true if tasks/cancel has been received for this task.
Cooperative: operations should check this and stop when set.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Resolves once tasks/cancel has been received for this task (or
immediately, if it already has). Cooperative: pair with
tokio::select! around long-running work to implement a cancellation
exit path.
An operation that stops in response should return
TaskExit::Cancelled so the task settles as cancelled. Returning
TaskExit::Error settles as failed, and finishing the work
anyway settles as completed — per SEP-2663 cancellation is
cooperative and a task may reach a non-cancelled terminal status.
Trait Implementations§
Source§impl Clone for TaskContext
impl Clone for TaskContext
Source§fn clone(&self) -> TaskContext
fn clone(&self) -> TaskContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TaskContext
impl RefUnwindSafe for TaskContext
impl Send for TaskContext
impl Sync for TaskContext
impl Unpin for TaskContext
impl UnsafeUnpin for TaskContext
impl UnwindSafe for TaskContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more