mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
20 lines
721 B
Swift
20 lines
721 B
Swift
public struct AgentSessionOwnership: Sendable {
|
|
private var authenticatedConnections: Set<Int32> = []
|
|
private var wasClaimed = false
|
|
|
|
public init() {}
|
|
|
|
public mutating func registerConnection(_ connection: Int32, authenticated: Bool) -> Bool {
|
|
guard authenticated else { return false }
|
|
let inserted = authenticatedConnections.insert(connection).inserted
|
|
guard inserted, !wasClaimed else { return false }
|
|
wasClaimed = true
|
|
return true
|
|
}
|
|
|
|
public mutating func disconnect(_ connection: Int32) -> Bool {
|
|
guard authenticatedConnections.remove(connection) != nil else { return false }
|
|
return wasClaimed && authenticatedConnections.isEmpty
|
|
}
|
|
}
|