Skip to content

Commit

Permalink
Minor changes:
Browse files Browse the repository at this point in the history
* Swift 6 support for async iterators
* Hide FlagChangeStream underlying iterator type
* & -> , in multiple conformance
  • Loading branch information
KeithBauerANZ committed Jul 23, 2024
1 parent b57afae commit 81dcd7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions Sources/Vexil/Observability/Observing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public typealias FlagChangeStream = AsyncStream<FlagChange>
public struct FilteredFlagChangeStream: AsyncSequence, Sendable {

public typealias Element = FlagChange
public typealias Failure = Never

let sequence: AsyncFilterSequence<FlagChangeStream>

Expand All @@ -49,8 +50,25 @@ public struct FilteredFlagChangeStream: AsyncSequence, Sendable {
}
}

public func makeAsyncIterator() -> AsyncFilterSequence<FlagChangeStream>.AsyncIterator {
sequence.makeAsyncIterator()
public struct AsyncIterator: AsyncIteratorProtocol {
var iterator: AsyncFilterSequence<FlagChangeStream>.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())
}

}
Expand All @@ -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
Expand All @@ -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
}

}
2 changes: 1 addition & 1 deletion Sources/Vexil/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 81dcd7b

Please sign in to comment.