TeraSessionGeneration.swift (1543B)
1 /// A transient callback guard. This value is never a persisted operation key. 2 struct TeraSessionGeneration: Sendable, Equatable, Hashable { 3 private let value: UInt64? 4 5 static let initial = Self(rawValue: 0) 6 7 init(rawValue: UInt64) { 8 value = rawValue 9 } 10 11 private init(exhausted _: Void) { 12 value = nil 13 } 14 15 var isActive: Bool { 16 value != nil 17 } 18 19 var diagnosticValue: String { 20 value.map(String.init) ?? "exhausted" 21 } 22 23 func requireActive() throws -> Self { 24 guard isActive else { 25 throw TeraStateTransitionError.generationOverflow 26 } 27 return self 28 } 29 30 func next() throws -> Self { 31 guard let value else { 32 throw TeraStateTransitionError.generationOverflow 33 } 34 return try Self(rawValue: TeraCheckedStateTransition.nextGeneration(after: value)) 35 } 36 37 /// Cleanup must invalidate old callbacks even when no further session can start. 38 func invalidated() -> Self { 39 (try? next()) ?? Self(exhausted: ()) 40 } 41 } 42 43 /// Diagnostic identity of an in-memory call, never the authored operation ID. 44 struct TeraRuntimeOperationIdentity: Sendable, Equatable, Hashable { 45 let generation: TeraSessionGeneration 46 let sequence: UInt64 47 let kind: TeraRuntimeOperationKind 48 49 var rawValue: String { 50 "ios-runtime-\(generation.diagnosticValue)-\(sequence)-\(kind.rawValue)" 51 } 52 } 53 54 /// Revision carried by a Rust invalidation hint, distinct from host sessions. 55 struct TeraProjectionRevision: Sendable, Equatable, Hashable { 56 let rawValue: UInt64? 57 58 static let exhausted = Self(rawValue: nil) 59 }