Skip to content

Basic cancellation support for long operations #60

@igor53627

Description

@igor53627

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

  1. Add TorError::Cancelled variant:
#[error("Operation cancelled")]
Cancelled,
  1. Add shutdown token to TorClient:
pub struct TorClient {
    shutdown_token: CancellationToken,  // from tokio-util
    // ...
}
  1. Wire into long operations:
tokio::select! {
    result = self.create_circuit() => result,
    _ = self.shutdown_token.cancelled() => Err(TorError::Cancelled),
}
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions