-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from stytchauth/jordan/fix-offline
Move to lazy delegates with custom getter to avoid race conditions with SharedPreferences
- Loading branch information
Showing
6 changed files
with
96 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
source/sdk/src/main/java/com/stytch/sdk/common/StytchLazyDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.stytch.sdk.common | ||
|
||
import kotlin.properties.ReadOnlyProperty | ||
import kotlin.reflect.KProperty | ||
|
||
internal class StytchLazyDelegate<T>( | ||
private val assertInitialized: () -> Unit, | ||
private val initializer: () -> T, | ||
) : ReadOnlyProperty<Any?, T> { | ||
private var value: T? = null | ||
|
||
override fun getValue( | ||
thisRef: Any?, | ||
property: KProperty<*>, | ||
): T { | ||
assertInitialized() | ||
if (value == null) { | ||
value = initializer() | ||
} | ||
return value!! | ||
} | ||
} |
Oops, something went wrong.