<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/ServerSocket/connections",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event12ServerSocketC11connectionsScsyAA0C0Cs5Error_pGvp"
  },
  "title" : "connections"
}
-->

# connections

An async stream of incoming connections, yielding each accepted [`Socket`](/documentation/Event/Socket).

```
var connections: AsyncThrowingStream<Socket, any Error> { get }
```

## Discussion

Loops [`accept()`](/documentation/Event/ServerSocket/accept()) in a detached `Task` and yields the resulting sockets via an
`AsyncThrowingStream`. The stream terminates when [`accept()`](/documentation/Event/ServerSocket/accept()) throws, propagating
the error to the consumer. A typical server loop looks like:

```swift
let server = try await Socket.listen(port: 8080)
for try await client in server.connections {
    Task { try await handleClient(client) }
}
```

> Note: Cancellation of the iterating task does not currently unregister the
> outstanding libevent accept callback. Drop the `ServerSocket` or call
> ``doc://Event/documentation/Event/ServerSocket/close()`` to ensure the listener is fully torn down.