-
-
Save mhjacobson/ad1a1dee71f3f0e50102d62b6af0d49f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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