From d1211f15e783fff251da76f86fa3e9efdeb68c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mlynari=C4=8D?= Date: Thu, 1 Feb 2024 13:50:33 +0100 Subject: [PATCH] Inline initialization Change-Id: I0a77eb6457cac27c1a4d604c8efdcbbdce95bc48 --- .../nowinandroid/util/ImageLoaderAsyncFactory.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/util/ImageLoaderAsyncFactory.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/util/ImageLoaderAsyncFactory.kt index 0670f6dc8..b746ec974 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/util/ImageLoaderAsyncFactory.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/util/ImageLoaderAsyncFactory.kt @@ -19,11 +19,11 @@ package com.google.samples.apps.nowinandroid.util import androidx.tracing.trace import coil.ImageLoader import coil.ImageLoaderFactory +import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.Default import com.google.samples.apps.nowinandroid.core.network.di.ApplicationScope import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.async -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import javax.inject.Inject @@ -41,14 +41,12 @@ class ImageLoaderAsyncFactory @Inject constructor( appScope: CoroutineScope, private val imageLoader: dagger.Lazy, ) : ImageLoaderFactory { - private lateinit var asyncNewImageLoader: Deferred - init { - asyncNewImageLoader = appScope.async { - // Initialize immediately, but need a Deferred for callers - imageLoader.get() - } - } + /** + * Initialize immediately, but need a Deferred for callers + * [ApplicationScope] already uses [Default] dispatcher, so we don't have to switch it here. + */ + private val asyncNewImageLoader: Deferred = appScope.async { imageLoader.get() } /** * This runBlocking here is on purpose to prevent any unfinished Coil initialization.