From 81dcd7b08a4a338ba2037f884c5462919d364799 Mon Sep 17 00:00:00 2001 From: Keith Bauer Date: Tue, 23 Jul 2024 08:47:10 +1200 Subject: [PATCH] Minor changes: * Swift 6 support for async iterators * Hide FlagChangeStream underlying iterator type * & -> , in multiple conformance --- Sources/Vexil/Observability/Observing.swift | 33 +++++++++++++++++++-- Sources/Vexil/Value.swift | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Sources/Vexil/Observability/Observing.swift b/Sources/Vexil/Observability/Observing.swift index 960d47d0..070ecc3c 100644 --- a/Sources/Vexil/Observability/Observing.swift +++ b/Sources/Vexil/Observability/Observing.swift @@ -33,6 +33,7 @@ public typealias FlagChangeStream = AsyncStream public struct FilteredFlagChangeStream: AsyncSequence, Sendable { public typealias Element = FlagChange + public typealias Failure = Never let sequence: AsyncFilterSequence @@ -49,8 +50,25 @@ public struct FilteredFlagChangeStream: AsyncSequence, Sendable { } } - public func makeAsyncIterator() -> AsyncFilterSequence.AsyncIterator { - sequence.makeAsyncIterator() + public struct AsyncIterator: AsyncIteratorProtocol { + var iterator: AsyncFilterSequence.AsyncIterator + + public mutating func next() async -> Element? { + await iterator.next() + } + +#if swift(>=6) + @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) + public mutating func next( + isolation actor: isolated (any Actor)? + ) async -> FlagChange? { + await iterator.next(isolation: actor) + } +#endif + } + + public func makeAsyncIterator() -> AsyncIterator { + AsyncIterator(iterator: sequence.makeAsyncIterator()) } } @@ -62,6 +80,7 @@ public struct FilteredFlagChangeStream: AsyncSequence, Sendable { public struct EmptyFlagChangeStream: AsyncSequence, Sendable { public typealias Element = FlagChange + public typealias Failure = Never public init() { // Intentionally left blank @@ -75,10 +94,18 @@ public struct EmptyFlagChangeStream: AsyncSequence, Sendable { public typealias Element = FlagChange - public func next() async throws -> FlagChange? { + public func next() async -> FlagChange? { nil } +#if swift(>=6) + @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) + public func next( + isolation actor: isolated (any Actor)? + ) async -> FlagChange? { + nil + } +#endif } } diff --git a/Sources/Vexil/Value.swift b/Sources/Vexil/Value.swift index 1ccbeb18..ff2919e5 100644 --- a/Sources/Vexil/Value.swift +++ b/Sources/Vexil/Value.swift @@ -67,7 +67,7 @@ public protocol FlagDisplayValue { /// /// Any custom type you conform to `FlagValue` must be able to be represented using one of these types /// -public enum BoxedFlagValue: Equatable & Sendable { +public enum BoxedFlagValue: Equatable, Sendable { case array([BoxedFlagValue]) case bool(Bool) case dictionary([String: BoxedFlagValue])