Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Kafka/KafkaConsumer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public final class KafkaConsumer: Sendable, Service {
var pollInterval = configuration.pollInterval
var events = [RDKafkaClient.KafkaEvent]()
events.reserveCapacity(100)
let clock = ContinuousClock()
while !Task.isCancelled {
let nextAction = self.stateMachine.withLockedValue { $0.nextEventPollLoopAction() }
switch nextAction {
Expand Down Expand Up @@ -526,7 +527,7 @@ public final class KafkaConsumer: Sendable, Service {
}
if shouldSleep {
pollInterval = min(self.configuration.pollInterval, pollInterval * 2)
try await Task.sleep(for: pollInterval)
try await clock.sleep(until: clock.now.advanced(by: pollInterval))
} else {
pollInterval = max(pollInterval / 3, .microseconds(1))
await Task.yield()
Expand Down
3 changes: 2 additions & 1 deletion Sources/Kafka/KafkaProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public final class KafkaProducer: Service, Sendable {
private func _run() async throws {
var pollInterval = self.configuration.pollInterval
var events = [RDKafkaClient.KafkaEvent]()
let clock = ContinuousClock()
while !Task.isCancelled {
let nextAction = self.stateMachine.withLockedValue { $0.nextPollLoopAction() }
switch nextAction {
Expand Down Expand Up @@ -288,7 +289,7 @@ public final class KafkaProducer: Service, Sendable {
}
if shouldSleep {
pollInterval = min(self.configuration.pollInterval, pollInterval * 2)
try await Task.sleep(for: pollInterval)
try await clock.sleep(until: clock.now.advanced(by: pollInterval))
} else {
pollInterval = max(pollInterval / 3, .microseconds(1))
await Task.yield()
Expand Down
Loading