Instance Method
stop()
Stop the Tor instance and release all associated resources.
func stop() async
Mentioned In
Discussion
Best-effort, non-throwing: if state is already TorState.idle, TorState.stopped, or TorState.failed(_:) the call is a no-op. Otherwise, the shutdown sequence:
Advances state to TorState.stopping and broadcasts a corresponding TorEvent.stateChanged(_:).
Sends SIGNAL SHUTDOWN over the control socket (control-spec.txt §3.7) via shutdown().
Polls the Tor thread for up to 10 seconds at 100 ms intervals, then Thread.cancel()s if the thread is still executing.
Releases the control client, closes the FD, and clears socksEndpoint.
If configuration.ownsDataDirectory is true, removes the data directory best-effort (errors are swallowed).
Advances state to TorState.stopped and finishes every outstanding events continuation.
Important
The 10 s grace window is deliberately shorter than Tor’s default ShutdownWaitLength (30 s) to bound the wait on misbehaving Tor builds; Thread.cancel() after that window is a best-effort unwind, not a guaranteed teardown.
Note
After resolution the TorClient is reusable — a subsequent start() re-enters TorState.starting with a fresh data directory when the configuration specifies an ephemeral path.