Skip to content

Commit 7d74670

Browse files
committed
review comments
1 parent 97590ac commit 7d74670

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Sources/NIOFileSystem/DirectoryEntries.swift

+3-5
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,
@@ -412,7 +412,6 @@ private struct DirectoryEnumerator: Sendable {
412412
case let .open(threadPool, _, _):
413413
return threadPool
414414
case .openPausedProducing(let threadPool, let source, let array):
415-
self.state = .modifying
416415
self.state = .open(threadPool, source, array)
417416
return threadPool
418417
case .done:
@@ -424,9 +423,8 @@ private struct DirectoryEnumerator: Sendable {
424423

425424
internal mutating func pauseProducing() {
426425
switch self.state {
427-
case .open(let nIOThreadPool, let source, let array):
428-
self.state = .modifying
429-
self.state = .openPausedProducing(nIOThreadPool, source, array)
426+
case .open(let threadPool, let source, let array):
427+
self.state = .openPausedProducing(threadPool, source, array)
430428
case .idle:
431429
() // we won't apply back pressure until something has been read
432430
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

0 commit comments

Comments
 (0)