Skip to content

Commit

Permalink
fix: start build() lazily (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
falconandy authored Oct 28, 2022
1 parent e04c72b commit d829ba7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion android/src/main/java/com/amplitude/android/Amplitude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.amplitude.id.FileIdentityStorageProvider
import com.amplitude.id.IdentityConfiguration
import com.amplitude.id.IdentityContainer
import com.amplitude.id.IdentityUpdateType
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
Expand All @@ -36,7 +37,7 @@ open class Amplitude(
override fun build(): Deferred<Boolean> {
val client = this

val built = amplitudeScope.async(amplitudeDispatcher) {
val built = amplitudeScope.async(amplitudeDispatcher, CoroutineStart.LAZY) {
storage = configuration.storageProvider.getStorage(client)

val storageDirectory = (configuration as Configuration).context.getDir("${FileStorage.STORAGE_PREFIX}-${configuration.instanceName}", Context.MODE_PRIVATE)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/amplitude/core/Amplitude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ open class Amplitude internal constructor(
timeline = this.createTimeline()
logger = configuration.loggerProvider.getLogger(this)
isBuilt = build()
isBuilt.start()
}

/**
Expand Down

0 comments on commit d829ba7

Please sign in to comment.