KMP-NativeCoroutines icon indicating copy to clipboard operation
KMP-NativeCoroutines copied to clipboard

Remove single value buffer from AsyncSequence implementation

Open rickclephas opened this issue 8 months ago • 0 comments
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.

rickclephas avatar Mar 04 '25 22:03 rickclephas