github AAkira/Napier 2.0.0-alpha1

latest releases: 2.7.1, 2.7.0, 2.6.1...
2 years ago
  • Update Kotlin 1.5.21
  • Run on other threads 🎉
    Thanks @PhilipDukhov

Example

You can use this library on a background thread on iOS using Kotlin.coroutines as native-mt.

  • Define coroutine scopes
internal val mainScope = SharedScope(Dispatchers.Main)

internal val backgroundScope = SharedScope(Dispatchers.Default)

internal class SharedScope(private val context: CoroutineContext) : CoroutineScope {
    private val job = Job()
    private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
        println("[Coroutine Exception] $throwable")
    }

    override val coroutineContext: CoroutineContext
        get() = context + job + exceptionHandler
}
  • Usage
backgroundScope.launch {
    suspendFunction()
}

Don't miss a new Napier release

NewReleases is sending notifications on new releases.