From bebba208692e9fd3f33286dc4ed4c25b1fa7d517 Mon Sep 17 00:00:00 2001 From: dkhawk <107309+dkhawk@users.noreply.github.com> Date: Tue, 26 Aug 2025 14:13:18 -0600 Subject: [PATCH] refactor: Convert addAttributionId to a suspend function Switch to the IO dispatcher inside the function. This ensures the scope is properly cleaned up. --- .../maps/android/compose/internal/MapsApiAttribution.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/internal/MapsApiAttribution.kt b/maps-compose/src/main/java/com/google/maps/android/compose/internal/MapsApiAttribution.kt index 5ebcfb20..0c59d8f6 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/internal/MapsApiAttribution.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/internal/MapsApiAttribution.kt @@ -6,9 +6,8 @@ import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateOf import com.google.android.gms.maps.MapsApiSettings import com.google.maps.android.compose.meta.AttributionId -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import java.util.concurrent.atomic.AtomicBoolean /** @@ -27,9 +26,9 @@ internal object MapsApiAttribution { * * @param context The context to use to add the attribution ID. */ - fun addAttributionId(context: Context) { + suspend fun addAttributionId(context: Context) { if (hasBeenCalled.compareAndSet(false, true)) { - CoroutineScope(Dispatchers.IO).launch { + withContext(Dispatchers.IO) { MapsApiSettings.addInternalUsageAttributionId(context, AttributionId.VALUE) _isInitialized.value = true }