Skip to content
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

Merged
merged 1 commit into from May 11, 2020

Conversation

zach-klippenstein
Copy link
Collaborator

Closes #1123.

Checklist

  • Unit Tests
  • UI Tests
  • Snapshot Tests (iOS only)
  • I have made corresponding changes to the documentation

@zach-klippenstein zach-klippenstein added the kotlin Affects the Kotlin library. label May 11, 2020
@zach-klippenstein zach-klippenstein added this to the v1.0.0 milestone May 11, 2020
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/remove-rxjava branch 2 times, most recently from 705b606 to 8a9ca38 Compare May 11, 2020 17:43
@rjrjr rjrjr added this to Reviewer approved in Workflow via automation May 11, 2020
Copy link
Contributor

@rjrjr rjrjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

Comment on lines +69 to +87
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"))
}
Copy link
Collaborator Author

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.

@zach-klippenstein zach-klippenstein merged commit 0bbc76f into master May 11, 2020
Workflow automation moved this from Reviewer approved to Done May 11, 2020
@zach-klippenstein zach-klippenstein deleted the zachklipp/remove-rxjava branch May 11, 2020 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kotlin Affects the Kotlin library.
Projects
Workflow
  
Done
Development

Successfully merging this pull request may close these issues.

Convert workflow-ui/core-android from Rx to Flow
2 participants