New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove RxJava2 dependency from Workflow Android UI integration. #1150
Conversation
705b606
to
8a9ca38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:D
kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowFragment.kt
Show resolved
Hide resolved
8a9ca38
to
eb44937
Compare
private val result = scope.async { | ||
session.outputs.first() | ||
} | ||
|
||
override suspend fun awaitResult(): OutputT = result.await() | ||
|
||
init { | ||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
session.renderingsAndSnapshots | ||
.map { it.snapshot } | ||
.onEach { lastSnapshot = it } | ||
.launchIn(scope) | ||
|
||
// Cancel the entire workflow runtime after the first output is emitted. | ||
// Use the Unconfined dispatcher to ensure the cancellation happens as immediately as possible. | ||
scope.launch(Dispatchers.Unconfined) { | ||
result.join() | ||
scope.cancel(CancellationException("WorkflowRunnerViewModel delivered result")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rjrjr FYI I just reworked this a bit. The result deferred is now created using async
, which is much more straightforward and means we don't have to manually propagate results and exceptions. The cancel-on-output logic is now responsible only for that, which I think makes it easier to read.
Closes #1123.
Checklist