Skip to content

Commit

Permalink
Use @available for NaiveQueueExecutor
Browse files Browse the repository at this point in the history
Can't use the current implementation before Swift 6.
  • Loading branch information
mimischi committed Nov 14, 2024
1 parent 5057a20 commit 9c4b7dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Kafka/KafkaConsumer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public struct KafkaConsumerMessages: Sendable, AsyncSequence {
public struct AsyncIterator: AsyncIteratorProtocol {
private let stateMachineHolder: MachineHolder
let pollInterval: Duration
#if swift(>=6.0)
let queue: NaiveQueueExecutor
#endif

private final class MachineHolder: Sendable { // only for deinit
let stateMachine: LockedMachine
Expand All @@ -90,7 +92,9 @@ public struct KafkaConsumerMessages: Sendable, AsyncSequence {
init(stateMachine: LockedMachine, pollInterval: Duration) {
self.stateMachineHolder = .init(stateMachine: stateMachine)
self.pollInterval = pollInterval
#if swift(>=6.0)
self.queue = NaiveQueueExecutor(DispatchQueue(label: "com.swift-server.swift-kafka.message-consumer"))
#endif
}

public func next() async throws -> Element? {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Kafka/Utilities/NaiveQueueExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=6.0)
import Dispatch

final class NaiveQueueExecutor: TaskExecutor {
Expand All @@ -35,3 +36,4 @@ final class NaiveQueueExecutor: TaskExecutor {
UnownedTaskExecutor(ordinary: self)
}
}
#endif

0 comments on commit 9c4b7dd

Please sign in to comment.