Inline initialization

Change-Id: I0a77eb6457cac27c1a4d604c8efdcbbdce95bc48
pull/1190/head
Tomáš Mlynarič 7 months ago
parent e853748cf7
commit d1211f15e7

@ -19,11 +19,11 @@ package com.google.samples.apps.nowinandroid.util
import androidx.tracing.trace import androidx.tracing.trace
import coil.ImageLoader import coil.ImageLoader
import coil.ImageLoaderFactory import coil.ImageLoaderFactory
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.Default
import com.google.samples.apps.nowinandroid.core.network.di.ApplicationScope import com.google.samples.apps.nowinandroid.core.network.di.ApplicationScope
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import javax.inject.Inject import javax.inject.Inject
@ -41,14 +41,12 @@ class ImageLoaderAsyncFactory @Inject constructor(
appScope: CoroutineScope, appScope: CoroutineScope,
private val imageLoader: dagger.Lazy<ImageLoader>, private val imageLoader: dagger.Lazy<ImageLoader>,
) : ImageLoaderFactory { ) : ImageLoaderFactory {
private lateinit var asyncNewImageLoader: Deferred<ImageLoader>
init { /**
asyncNewImageLoader = appScope.async { * Initialize immediately, but need a Deferred for callers
// Initialize immediately, but need a Deferred for callers * [ApplicationScope] already uses [Default] dispatcher, so we don't have to switch it here.
imageLoader.get() */
} private val asyncNewImageLoader: Deferred<ImageLoader> = appScope.async { imageLoader.get() }
}
/** /**
* This runBlocking here is on purpose to prevent any unfinished Coil initialization. * This runBlocking here is on purpose to prevent any unfinished Coil initialization.

Loading…
Cancel
Save