Skip to content

Commit

Permalink
chore: Use trySend() instead of offer()
Browse files Browse the repository at this point in the history
  • Loading branch information
barbeau committed Aug 16, 2021
1 parent a64af1d commit c259d8d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 3 additions & 0 deletions complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ dependencies {

implementation 'com.google.android.material:material:1.3.0'

// To use trySend() instead of offer() in callbackFlow (see https://github.com/Kotlin/kotlinx.coroutines/issues/974)
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'

// Hilt for dependency injection
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ class SharedLocationManager constructor(
override fun onLocationResult(result: LocationResult?) {
result ?: return
Log.d(TAG, "New location: ${result.lastLocation.toText()}")
try {
offer(result.lastLocation) // emit location into the Flow using ProducerScope.offer
} catch (e: Exception) {
// nothing to do
// Channel was probably already closed by the time offer was called
}
trySend(result.lastLocation)
}
}

Expand Down

0 comments on commit c259d8d

Please sign in to comment.