Skip to content
Merged
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
8 changes: 7 additions & 1 deletion Sources/Subprocess/SubprocessOutputSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import os
#endif

/// An asynchronous sequence of buffers that streams output from a subprocess.
///
/// - Important: This sequence is single-pass and can be iterated only once.
/// See ``makeAsyncIterator()``.
public struct SubprocessOutputSequence: AsyncSequence, @unchecked Sendable {
/// The failure type for the asynchronous sequence.
public typealias Failure = any Swift.Error
Expand Down Expand Up @@ -110,9 +113,12 @@ public struct SubprocessOutputSequence: AsyncSequence, @unchecked Sendable {
}

/// Creates an iterator for this asynchronous sequence.
///
/// - Precondition: `SubprocessOutputSequence` is single-pass; creating a
/// second iterator results in a fatal error.
public func makeAsyncIterator() -> Iterator {
guard self.state.initializedCount() == 1 else {
fatalError("SubprocessOutputSequence is single pass. It can only be iterated once.")
fatalError("SubprocessOutputSequence is single-pass. It can only be iterated once.")
}
return Iterator(diskIO: self.diskIO, processIdentifier: self.processIdentifier)
}
Expand Down