Skip to content

Commit 41fe2de

Browse files
committed
review comments
1 parent 97590ac commit 41fe2de

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Sources/NIOFileSystem/DirectoryEntries.swift

+3-6
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension DirectoryEntries.Batched.AsyncIterator: Sendable {}
136136
// MARK: - Internal
137137

138138
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
139-
extension NIOThrowingAsyncSequenceProducer where Element == [DirectoryEntry], Failure == Error,
139+
extension NIOThrowingAsyncSequenceProducer where Element == [DirectoryEntry], Failure == (any Error),
140140
Strategy == NIOAsyncSequenceProducerBackPressureStrategies.HighLowWatermark, Delegate == DirectoryEntryProducer {
141141
fileprivate static func makeBatchedDirectoryEntryStream(
142142
handle: SystemFileHandle,
@@ -270,7 +270,6 @@ fileprivate final class DirectoryEntryProducer: NIOAsyncSequenceProducerDelegate
270270
}
271271

272272
private func onNextBatch(_ entries: [DirectoryEntry]) {
273-
274273
let source = self.state.withLockedValue { state in
275274
return state.sequenceProducerSource
276275
}
@@ -412,7 +411,6 @@ private struct DirectoryEnumerator: Sendable {
412411
case let .open(threadPool, _, _):
413412
return threadPool
414413
case .openPausedProducing(let threadPool, let source, let array):
415-
self.state = .modifying
416414
self.state = .open(threadPool, source, array)
417415
return threadPool
418416
case .done:
@@ -424,9 +422,8 @@ private struct DirectoryEnumerator: Sendable {
424422

425423
internal mutating func pauseProducing() {
426424
switch self.state {
427-
case .open(let nIOThreadPool, let source, let array):
428-
self.state = .modifying
429-
self.state = .openPausedProducing(nIOThreadPool, source, array)
425+
case .open(let threadPool, let source, let array):
426+
self.state = .openPausedProducing(threadPool, source, array)
430427
case .idle:
431428
() // we won't apply back pressure until something has been read
432429
case .openPausedProducing, .done:

Sources/NIOFileSystem/FileChunks.swift

+10-7
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ private final class FileChunkProducer: NIOAsyncSequenceProducerDelegate, Sendabl
129129
let length: Int64
130130

131131
init(range: FileChunks.ChunkRange, handle: SystemFileHandle, length: Int64) {
132-
133-
let state: ProducerState = switch range {
132+
let state: ProducerState
133+
switch range {
134134
case .entireFile:
135-
.init(handle: handle, range: nil)
135+
state = .init(handle: handle, range: nil)
136136
case .partial(let partialRange):
137-
.init(handle: handle, range: partialRange)
137+
state = .init(handle: handle, range: partialRange)
138138
}
139139

140140
self.state = NIOLockedValueBox(state)
@@ -357,13 +357,13 @@ private struct ProducerState: Sendable {
357357
mutating func didReadBytes(_ count: Int) {
358358
switch self.state {
359359
case var .producing(state):
360-
if state.updateRange(count: count) {
360+
if state.didReadBytes(count) {
361361
self.state = .done(emptyRange: false)
362362
} else {
363363
self.state = .producing(state)
364364
}
365365
case var .pausedProducing(state):
366-
if state.updateRange(count: count) {
366+
if state.didReadBytes(count) {
367367
self.state = .done(emptyRange: false)
368368
} else {
369369
self.state = .pausedProducing(state)
@@ -399,7 +399,10 @@ private struct ProducerState: Sendable {
399399

400400
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
401401
extension ProducerState.Producing {
402-
mutating func updateRange(count: Int) -> Bool {
402+
/// Updates the range (the offsets to read from and up to) to reflect the number of bytes which have been read.
403+
/// - Parameter count: The number of bytes which have been read.
404+
/// - Returns: Returns `True` if there are no remaining bytes to read, `False` otherwise.
405+
mutating func didReadBytes(_ count: Int) -> Bool {
403406
guard let currentRange = self.range else {
404407
// if we read 0 bytes we are done
405408
return count == 0

Sources/NIOFileSystem/Internal/BufferedOrAnyStream.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal enum BufferedOrAnyStream<Element, Delegate: NIOAsyncSequenceProducerDel
4747
internal mutating func next() async throws -> Element? {
4848
let element: Element?
4949
switch self {
50-
case var .bufferedStream(iterator):
50+
case let .bufferedStream(iterator):
5151
defer { self = .bufferedStream(iterator) }
5252
element = try await iterator.next()
5353
case var .anyAsyncSequence(iterator):

0 commit comments

Comments
 (0)