KMP-NativeCoroutines
KMP-NativeCoroutines copied to clipboard
Remove single value buffer from AsyncSequence implementation
trafficstars
Only the first emitted value needs to be buffered. Once we have consumed the first value we can wait for a call to Iterator.next before invoking the next callback from Kotlin.
This will make sure that emit in Kotlin suspends until Swift calls Iterator.next to get the next value.
We could even delay the Flow collection until the first call to Iterator.next.
Which would allow us to remove the item buffer completely.
Although in that case we'll need a fatalError for the nil check on continuation.