1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Cooperative cancellation for long-running session operations.
//!
//! The token is deliberately just one atomic bit. Policy stays with the
//! caller: UI code, request handlers, or worker supervisors decide when to
//! flip the bit; `lean-rs-host` only checks it at documented boundaries.
use Arc;
use ;
use LeanResult;
/// Shared cooperative cancellation token for `LeanSession` calls.
///
/// `LeanCancellationToken` is `Clone + Send + Sync`, so a coordinator
/// thread can keep one clone and the Lean-bound worker thread can pass
/// another clone by reference to session methods. Cancelling sets one
/// atomic bit. Session methods check that bit before FFI dispatches and,
/// for token-aware bulk paths, between per-item dispatches.
///
/// This is not pre-emptive cancellation. It does **not** interrupt an
/// in-flight Lean call. In particular, it cannot stop one stuck `isDefEq`,
/// a C-side kernel reduction that does not check heartbeats, or an
/// `@[export]` symbol that runs its own long loop without returning to a
/// `lean-rs-host` check point. Bound those workloads with Lean heartbeat
/// options, caller-level timeouts, or a worker-process boundary.
///
/// ```no_run
/// use std::thread;
/// use lean_rs_host::LeanCancellationToken;
///
/// let token = LeanCancellationToken::new();
/// let canceller = token.clone();
///
/// thread::spawn(move || {
/// // A UI event, request timeout, or supervisor decision would live here.
/// canceller.cancel();
/// });
///
/// // On the Lean worker thread:
/// // session.query_declarations_bulk(&names, Some(&token), None)?;
/// # let _ = token;
/// ```
pub