Created
July 16, 2021 11:17
-
-
Save cmelchior/132297dc9365c0427ca11e9201ebfef2 to your computer and use it in GitHub Desktop.
Realm Kotlin 0.40 Release Blog Post - Opening Realms
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
// Global App variable | |
class MyApp: Application() { | |
companion object { | |
private val config = RealmConfiguration(schema = setOf(Person::class)) | |
public val REALM = Realm(config) | |
} | |
} | |
// Using dependency injection | |
val koinModule = module { | |
single { RealmConfiguration(schema = setOf(Person::class)) } | |
single { Realm(get()) } | |
} | |
// Realms are now thread safe | |
val realm = Realm(config) | |
val t1 = Thread { | |
realm.writeBlocking { /* ... */ } | |
} | |
val t2 = Thread { | |
val queryResult = realm.objects(Person::class) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment