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
ⓘ
use fraiseql_core::runtime::ExecutionContext;
use tokio_util::sync::CancellationToken;
let token = CancellationToken::new();
let ctx = ExecutionContext::new("query-123".to_string(), token);
// 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, Some(&ctx)).await;Implementations§
Source§impl ExecutionContext
impl ExecutionContext
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub 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