Overview
Add cancellation/abort support so JS can cancel long-running operations like circuit building.
Problem
- WASM bindings return plain Promises with no cancellation API
- JS cannot pass
AbortSignal to operations
- Long operations continue running even if user navigates away
- No
TorError::Cancelled variant to distinguish user-initiated aborts
Solution (incremental approach)
Phase 1: Internal cancellation token
- Add
TorError::Cancelled variant:
#[error("Operation cancelled")]
Cancelled,
- Add shutdown token to
TorClient:
pub struct TorClient {
shutdown_token: CancellationToken, // from tokio-util
// ...
}
- Wire into long operations:
tokio::select! {
result = self.create_circuit() => result,
_ = self.shutdown_token.cancelled() => Err(TorError::Cancelled),
}
- Expose abort method in WASM:
#[wasm_bindgen]
impl TorClient {
pub fn abort(&self) {
self.shutdown_token.cancel();
}
}
Phase 2 (future): Per-operation AbortSignal
- Accept JS
AbortSignal in fetch() and other methods
- Map to internal cancellation tokens
Files to modify
webtor/src/error.rs - Add Cancelled variant
webtor/src/client.rs - Add shutdown token, wire into ops
webtor-wasm/src/lib.rs - Expose abort() method
Cargo.toml - Add tokio-util dependency (if not present)
Effort
M-L (4-8 hours)
Priority
P3 - Nice to have for UX, but timeouts (#59) cover most cases
Depends on
Overview
Add cancellation/abort support so JS can cancel long-running operations like circuit building.
Problem
AbortSignalto operationsTorError::Cancelledvariant to distinguish user-initiated abortsSolution (incremental approach)
Phase 1: Internal cancellation token
TorError::Cancelledvariant:TorClient:Phase 2 (future): Per-operation AbortSignal
AbortSignalinfetch()and other methodsFiles to modify
webtor/src/error.rs- AddCancelledvariantwebtor/src/client.rs- Add shutdown token, wire into opswebtor-wasm/src/lib.rs- Exposeabort()methodCargo.toml- Addtokio-utildependency (if not present)Effort
M-L (4-8 hours)
Priority
P3 - Nice to have for UX, but timeouts (#59) cover most cases
Depends on
Cancellederror handling in JS)