pub struct ExecutionContext { /* private fields */ }Expand description
Execution context for query cancellation support.
This struct provides a mechanism for gracefully cancelling long-running queries via cancellation tokens, enabling proper cleanup and error reporting when:
- A client connection closes
- A user explicitly cancels a query
- A system shutdown is initiated
§Example
// Requires: a running tokio runtime and an Executor with a live database adapter.
// See: tests/integration/ for runnable examples.
use fraiseql_core::runtime::ExecutionContext;
use std::time::Duration;
let ctx = ExecutionContext::new("query-123".to_string());
// Spawn a task that cancels after 5 seconds
let cancel_token = ctx.cancellation_token().clone();
tokio::spawn(async move {
tokio::time::sleep(Duration::from_secs(5)).await;
cancel_token.cancel();
});
// Execute query with cancellation support
// let result = executor.execute_with_context(query, None, &ctx).await;Implementations§
Source§impl ExecutionContext
impl ExecutionContext
Sourcepub const fn cancellation_token(&self) -> &CancellationToken
pub const fn cancellation_token(&self) -> &CancellationToken
Get a reference to the cancellation token.
The returned token can be used to:
- Clone and pass to background tasks
- Check if cancellation was requested
- Propagate cancellation through the call stack
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if cancellation has been requested.
Trait Implementations§
Source§impl Clone for ExecutionContext
impl Clone for ExecutionContext
Source§fn clone(&self) -> ExecutionContext
fn clone(&self) -> ExecutionContext
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 ExecutionContext
impl RefUnwindSafe for ExecutionContext
impl Send for ExecutionContext
impl Sync for ExecutionContext
impl Unpin for ExecutionContext
impl UnsafeUnpin for ExecutionContext
impl UnwindSafe for ExecutionContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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