Skip to content

Commit 3194c2a

Browse files
authored
refactor: Convert addAttributionId to a suspend function (#742)
Switch to the IO dispatcher inside the function. This ensures the scope is properly cleaned up.
1 parent b3902e9 commit 3194c2a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

maps-compose/src/main/java/com/google/maps/android/compose/internal/MapsApiAttribution.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import androidx.compose.runtime.State
66
import androidx.compose.runtime.mutableStateOf
77
import com.google.android.gms.maps.MapsApiSettings
88
import com.google.maps.android.compose.meta.AttributionId
9-
import kotlinx.coroutines.CoroutineScope
109
import kotlinx.coroutines.Dispatchers
11-
import kotlinx.coroutines.launch
10+
import kotlinx.coroutines.withContext
1211
import java.util.concurrent.atomic.AtomicBoolean
1312

1413
/**
@@ -27,9 +26,9 @@ internal object MapsApiAttribution {
2726
*
2827
* @param context The context to use to add the attribution ID.
2928
*/
30-
fun addAttributionId(context: Context) {
29+
suspend fun addAttributionId(context: Context) {
3130
if (hasBeenCalled.compareAndSet(false, true)) {
32-
CoroutineScope(Dispatchers.IO).launch {
31+
withContext(Dispatchers.IO) {
3332
MapsApiSettings.addInternalUsageAttributionId(context, AttributionId.VALUE)
3433
_isInitialized.value = true
3534
}

0 commit comments

Comments
 (0)