Skip to content

Commit c259d8d

Browse files
committedAug 16, 2021
chore: Use trySend() instead of offer()
See Kotlin/kotlinx.coroutines#974
1 parent a64af1d commit c259d8d

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed
 

‎complete/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ dependencies {
6565

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

68+
// To use trySend() instead of offer() in callbackFlow (see https://github.com/Kotlin/kotlinx.coroutines/issues/974)
69+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
70+
6871
// Hilt for dependency injection
6972
implementation "com.google.dagger:hilt-android:$hilt_version"
7073
kapt "com.google.dagger:hilt-compiler:$hilt_version"

‎complete/src/main/java/com/example/android/whileinuselocation/data/SharedLocationManager.kt

+1-6
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ class SharedLocationManager constructor(
7171
override fun onLocationResult(result: LocationResult?) {
7272
result ?: return
7373
Log.d(TAG, "New location: ${result.lastLocation.toText()}")
74-
try {
75-
offer(result.lastLocation) // emit location into the Flow using ProducerScope.offer
76-
} catch (e: Exception) {
77-
// nothing to do
78-
// Channel was probably already closed by the time offer was called
79-
}
74+
trySend(result.lastLocation)
8075
}
8176
}
8277

0 commit comments

Comments
 (0)
Please sign in to comment.