Skip to content

Instantly share code, notes, and snippets.

@cmelchior
Created July 16, 2021 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmelchior/132297dc9365c0427ca11e9201ebfef2 to your computer and use it in GitHub Desktop.
Save cmelchior/132297dc9365c0427ca11e9201ebfef2 to your computer and use it in GitHub Desktop.
Realm Kotlin 0.40 Release Blog Post - Opening Realms
// 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