Skip to content

Commit d1211f1

Browse files
committed
Inline initialization
Change-Id: I0a77eb6457cac27c1a4d604c8efdcbbdce95bc48
1 parent e853748 commit d1211f1

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

app/src/main/java/com/google/samples/apps/nowinandroid/util/ImageLoaderAsyncFactory.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ package com.google.samples.apps.nowinandroid.util
1919
import androidx.tracing.trace
2020
import coil.ImageLoader
2121
import coil.ImageLoaderFactory
22+
import com.google.samples.apps.nowinandroid.core.network.NiaDispatchers.Default
2223
import com.google.samples.apps.nowinandroid.core.network.di.ApplicationScope
2324
import kotlinx.coroutines.CoroutineScope
2425
import kotlinx.coroutines.Deferred
2526
import kotlinx.coroutines.async
26-
import kotlinx.coroutines.launch
2727
import kotlinx.coroutines.runBlocking
2828
import javax.inject.Inject
2929

@@ -41,14 +41,12 @@ class ImageLoaderAsyncFactory @Inject constructor(
4141
appScope: CoroutineScope,
4242
private val imageLoader: dagger.Lazy<ImageLoader>,
4343
) : ImageLoaderFactory {
44-
private lateinit var asyncNewImageLoader: Deferred<ImageLoader>
4544

46-
init {
47-
asyncNewImageLoader = appScope.async {
48-
// Initialize immediately, but need a Deferred for callers
49-
imageLoader.get()
50-
}
51-
}
45+
/**
46+
* Initialize immediately, but need a Deferred for callers
47+
* [ApplicationScope] already uses [Default] dispatcher, so we don't have to switch it here.
48+
*/
49+
private val asyncNewImageLoader: Deferred<ImageLoader> = appScope.async { imageLoader.get() }
5250

5351
/**
5452
* This runBlocking here is on purpose to prevent any unfinished Coil initialization.

0 commit comments

Comments
 (0)