
commonMain.korlibs.inject.AsyncInjectorSuspendContext.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of korinject-jvm Show documentation
Show all versions of korinject-jvm Show documentation
Asynchronous Injector for Kotlin
package korlibs.inject
import kotlinx.coroutines.*
import kotlin.coroutines.*
suspend fun withInjector(injector: AsyncInjector, block: suspend () -> T): T =
withContext(AsyncInjectorContext(injector)) {
block()
}
suspend fun injector(): AsyncInjector =
coroutineContext[AsyncInjectorContext]?.injector
?: error("AsyncInjector not in the context, please call withInjector function")
class AsyncInjectorContext(val injector: AsyncInjector) : CoroutineContext.Element {
companion object : CoroutineContext.Key
override val key get() = AsyncInjectorContext
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy