Skip to content

Commit

Permalink
Move lockstepSplit extension to AsyncSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
saagarjha committed Nov 22, 2023
1 parent aeb6160 commit b808bb0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions unxip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ struct Queue<Element> {
}

extension AsyncThrowingStream where Failure == Error {
actor PermissiveActionLink {
var iterator: Iterator
actor PermissiveActionLink<S: AsyncSequence> where S.Element == Element {
var iterator: S.AsyncIterator
let count: Int
var queued = [CheckedContinuation<Element?, Error>]()

init(iterator: Iterator, count: Int) {
init(iterator: S.AsyncIterator, count: Int) {
self.iterator = iterator
self.count = count
}
Expand Down Expand Up @@ -1371,15 +1371,15 @@ public struct Unxip {
}
}

extension AsyncThrowingStream where Failure == Error {
public func lockstepSplit() -> (Self, Self) {
let pal = PermissiveActionLink(iterator: makeAsyncIterator(), count: 2)
extension AsyncSequence {
public func lockstepSplit() -> (AsyncThrowingStream<Element, Error>, AsyncThrowingStream<Element, Error>) {
let pal = AsyncThrowingStream.PermissiveActionLink<Self>(iterator: makeAsyncIterator(), count: 2)

return (
Self {
.init {
try await pal.next()
},
Self {
.init {
try await pal.next()
}
)
Expand Down Expand Up @@ -1592,7 +1592,7 @@ extension AsyncThrowingStream where Failure == Error {
}
}

let file = AsyncThrowingStream(erasing: DataReader.data(readingFrom: handle.fileDescriptor))
let file = DataReader.data(readingFrom: handle.fileDescriptor)
let (data, input) = file.lockstepSplit()

Task {
Expand Down

0 comments on commit b808bb0

Please sign in to comment.