Overview
Concrete tool for enforcing query timeouts by tripping a cancellation token after a deadline provided by the sqmeow-core engine.
Description
The Deadline struct spawns a timer that trips a CancellationToken after timeout_ms milliseconds. When timeout_ms is 0, no timer is created (no limit). The passed() method distinguishes a deadline-triggered cancellation from a user-initiated one, so the error message can say "ran past the timeout" instead of "cancelled". The timer task is aborted on drop, so dropping the Deadline stops the timeout.
Usage
- Query execution: Created before running statements; cancels the call if it runs past
options.timeout_ms.
- In-grid editing: Created before applying DML statements; cancels the apply if it runs past the timeout.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-core/src/server/calls.rs
- Lines: L36-68
Signature
pub(super) struct Deadline {
timer: Option<tokio::task::JoinHandle<()>>,
passed: Arc<AtomicBool>,
}
impl Deadline {
pub(super) fn start(token: CancellationToken, timeout_ms: u64) -> Self;
pub(super) fn passed(&self) -> bool;
}
Import
use super::calls::Deadline;
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| token |
CancellationToken |
Yes /// Call's cancellation token to trip
|
| timeout_ms |
u64 |
Yes /// Deadline in milliseconds (0 = no limit)
|
Outputs
| Name |
Type |
Description
|
| passed |
bool /// Whether the deadline (not a cancel) tripped the token
|
Usage Examples
Enforcing a query timeout
let running = session.begin_call(call_id);
let deadline = Deadline::start(running.token(), options.timeout_ms);
// ... execute query ...
match outcome {
Err(DbError::Cancelled) if deadline.passed() => {
// "the query ran past the 5000 ms timeout, so it was cancelled"
}
Err(DbError::Cancelled) => {
// "cancelled" (user-initiated)
}
_ => { /* success or other error */ }
}
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.