<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/TorClient/start()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor0A6ClientC5startyyYaKF"
  },
  "title" : "start()"
}
-->

# start()

Start the embedded Tor process.

```
func start() async throws
```

## Discussion

Orchestrates the cross-thread dance that brings Tor up:

1. Create ``doc://Tor/documentation/Tor/TorConfiguration/dataDirectory`` (and parents) with
   `FileManager.createDirectory(atPath:withIntermediateDirectories:)`.
1. Call `tor_main_configuration_new()`, stamp the configuration
   with our torrc-equivalent argv, and hand it
   `tor_main_configuration_setup_control_socket()` to obtain a
   pre-authenticated embedded control socket.
1. Post `tor_run_main()` to a dedicated `Thread`; bridge its
   synchronous startup back to the actor with a
   `CheckedContinuation`.
1. Bind a ``doc://Tor/documentation/Tor/TorControlClient`` to the socket and populate
   ``doc://Tor/documentation/Tor/TorClient/socksEndpoint`` via `GETINFO net/listeners/socks`
   (control-spec.txt §3.9).

Resolves once steps 1–4 complete, at which point [`state`](/documentation/Tor/TorClient/state)
advances to [`TorState.running`](/documentation/Tor/TorState/running). Bootstrap progress is still in
flight — pair with [`waitUntilBootstrapped(timeout:)`](/documentation/Tor/TorClient/waitUntilBootstrapped(timeout:)) to block
until Tor is actually ready to carry user traffic.

> Throws: ``doc://Tor/documentation/Tor/TorError/alreadyStarted`` when ``doc://Tor/documentation/Tor/TorClient/state`` is
> ``doc://Tor/documentation/Tor/TorState/starting``, ``doc://Tor/documentation/Tor/TorState/running``, or
> ``doc://Tor/documentation/Tor/TorState/stopping``; ``doc://Tor/documentation/Tor/TorError/startFailed(_:)`` when
> `tor_run_main()` returns non-zero or the argv is rejected.

> Important: This method is idempotent only for terminal states
> (``doc://Tor/documentation/Tor/TorState/idle``, ``doc://Tor/documentation/Tor/TorState/stopped``, ``doc://Tor/documentation/Tor/TorState/failed(_:)``);
> double-starting while ``doc://Tor/documentation/Tor/TorClient/state`` is transient throws.