Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,11 @@ class NavigationViewModel(
try {
val routeStatusFuture = localNavigator.setDestination(destination, routingOptions)

// Do not cancel routeStatusFuture when this coroutine is cancelled: the Navigation SDK
// rethrows "Task was cancelled" on the main thread when it delivers a cancelled future,
// which crashes the app. A newer setDestination() or clearDestinations() call already
// supersedes the pending route, and the listener below ignores late results.
suspendCancellableCoroutine { continuation ->
continuation.invokeOnCancellation {
routeStatusFuture.cancel(true)
}
val callback =
ListenableResultFuture.OnResultListener<Navigator.RouteStatus> { status ->
if (!continuation.isActive) return@OnResultListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ class NavigationViewModelTest {
viewModel.navigateToLatLng(LatLng(40.0150, -105.2705), label = "Second Destination")
advanceUntilIdle()

verify { firstFuture.cancel(true) }
// Cancelling the SDK future makes it throw "Task was cancelled" on the main thread.
verify(exactly = 0) { firstFuture.cancel(any()) }
// Even if the SDK invokes the canceled first callback with ROUTE_CANCELED, state stays RUNNING
if (firstListenerSlot.isCaptured) {
firstListenerSlot.captured.onResult(Navigator.RouteStatus.ROUTE_CANCELED)
Expand Down