Instance Property
connections
An async stream of incoming connections, yielding each accepted Socket.
var connections: AsyncThrowingStream<Socket, any Error> { get }
Mentioned In
Discussion
Loops accept() in a detached Task and yields the resulting sockets via an AsyncThrowingStream. The stream terminates when accept() throws, propagating the error to the consumer. A typical server loop looks like:
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 close() to ensure the listener is fully torn down.