Skip to content

Instantly share code, notes, and snippets.

@mhjacobson
Created March 25, 2022 22:49
Show Gist options
  • Save mhjacobson/ad1a1dee71f3f0e50102d62b6af0d49f to your computer and use it in GitHub Desktop.
Save mhjacobson/ad1a1dee71f3f0e50102d62b6af0d49f to your computer and use it in GitHub Desktop.
import Darwin
let iterator = AsyncBufferedByteIterator(capacity: 100) { buffer in
let value = UInt8.random(in: UInt8.min...UInt8.max)
for i in 0..<100 {
buffer.storeBytes(of: value, toByteOffset: i * MemoryLayout<UInt8>.size, as: UInt8.self)
}
return 100
}
for _ in 0..<2 {
Task {
var iteratorCopy = iterator
while true {
let firstValue = try! await iteratorCopy.next()
for _ in 0..<99 {
let value = try! await iteratorCopy.next()
precondition(value == firstValue)
}
}
}
}
pthread_exit(nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment