Skip to content

Commit

Permalink
Fixed an issue where disk file handles for memory cached data were he…
Browse files Browse the repository at this point in the history
…ld open indefinitely
  • Loading branch information
dimitribouniol committed Jul 29, 2024
1 parent bb6772f commit a0607f9
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ actor MultiplexedAsyncSequence<Base: AsyncSequence & Sendable>: AsyncSequence wh
typealias Element = Base.Element

private var cachedEntries: [Task<Element?, Error>] = []
private var baseIterator: Base.AsyncIterator
private var baseIterator: Base.AsyncIterator?

struct AsyncIterator: AsyncIteratorProtocol & Sendable {
let base: MultiplexedAsyncSequence
Expand Down Expand Up @@ -206,10 +206,11 @@ actor MultiplexedAsyncSequence<Base: AsyncSequence & Sendable>: AsyncSequence wh
}
}

nonisolated func nextBase(iterator: Base.AsyncIterator) async throws -> (Element?, Base.AsyncIterator) {
/// Return the next base iterator to use along with the current entry, or nil if we've reached the end, so we don't retail the open file handles in our memory caches.
nonisolated func nextBase(iterator: Base.AsyncIterator?) async throws -> (Element?, Base.AsyncIterator?) {
var iteratorCopy = iterator
let nextEntry = try await iteratorCopy.next()
return (nextEntry, iteratorCopy)
let nextEntry = try await iteratorCopy?.next()
return (nextEntry, nextEntry.flatMap { _ in iteratorCopy })
}

nonisolated func makeAsyncIterator() -> AsyncIterator {
Expand Down

0 comments on commit a0607f9

Please sign in to comment.