Repository navigation
JNI: AsyncThrowingStream results, with errors delivered to onError - #15
Open
piercifani wants to merge 2 commits into
Open
piercifani wants to merge 2 commits into
piercifani wants to merge 2 commits into
Conversation
This was referenced Nov 3, 2026
Functions returning `AsyncThrowingStream<T, Failure>` were skipped: the type wasn't in the modeled standard library. - The generator treats them like `AsyncStream<T>`: Java gets the same `SwiftAsyncStream<T>` and the Swift thunk calls `_attachAsyncStream`, which gains an `AsyncThrowingStream` overload. - When the stream throws, the error is converted like any thrown Swift error and delivered to the new `Subscriber.onError` instead of `onComplete`. Neither is called after the subscription is cancelled. - SwiftKitKotlin's `asFlow()` closes the flow with that error, so `collect` throws it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
piercifani
force-pushed
the
jni/11-async-throwing-stream
branch
from
November 3, 2026 16:46
47472fb to
ce59fd8
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack 11/21 · base:
jni/10-async-stream· previous: #14 · next: #16 (jni/12-optional-nested-arrays)Problem
jextract skipped functions returning
AsyncThrowingStream<T, Failure>, because the type isn't in its model of the standard library. #14 handledAsyncStreamonly.Changes
Generator.
AsyncThrowingStreamis added to the stdlib model next toAsyncStream. A function returningAsyncThrowingStream<T, Failure>is translated exactly like one returningAsyncStream<T>: Java gets aSwiftAsyncStream<T>, and the Swift thunk calls_attachAsyncStream. BothErrorandany Errorfailures are covered.Runtime.
_attachAsyncStreamgains anAsyncThrowingStreamoverload, so the generated code is the same for both stream types. Both overloads share one task body. When the stream throws, the error is converted to a JavaThrowablethe same way a thrown Swift error is for any call: a jextracted error type becomes its own exception class, and any other error becomesSwiftErrorException.Java.
SwiftAsyncStream.Subscribergetsdefault void onError(Throwable error), called instead ofonCompletewhen a throwing stream fails. Neither one is called after the subscription is cancelled; theDeliverythat already guarantees one finish now covers the error path too.Kotlin.
SwiftKitKotlin'sasFlow()closes the flow with that error, socollectthrows the Swift error.Kotlin in this PR
StreamsTest.ktwithStreams.swift:The Swift stream yields two items and then finishes with
throwing: ClientError.offline. Kotlin receives both items and then catches the typed Swift error, matching on its case.Why Skip needs it
Skip bridges
AsyncThrowingStreamto a KotlinFlowthat fails with the error, the same way it bridgesAsyncStream.Testing
./gradlew :SwiftKitKotlin:build :Samples:SwiftJavaExtractJNIKotlinSampleApp:testpasses (30 tests).JNIAsyncStreamTests: a new parameterized test forAsyncThrowingStream<Int64, Error>and<Int64, any Error>checks the Java method, the native signature and the Swift attach call.interruptedCountdowndelivers its elements and then its error toonError, with the Swift description as the message.swift test --disable-experimental-prebuilts --disable-sandbox(654 tests) and./gradlew :Samples:SwiftJavaExtractJNISampleApp:test(288 tests) pass.swift format lint --stricton changed files;git diff --check.Not in this PR
AsyncSequencetypes, and streams as parameters or properties.Failureisn't reflected in Java: every stream is aSwiftAsyncStream<T>, and the error arrives as aThrowable.🤖 Generated with Claude Code