
Enhances coroutine context management in suspending functions through annotations, simplifying code readability by eliminating the need for `withContext` calls.
suspend-kontext is a Kotlin Compiler Plugin that allows you to specify the default coroutine context for suspending functions using annotations.
Switching coroutine contexts typically requires the use of withContext, like this:
suspend fun loadText(file: File): String {
return withContext(Dispatchers.IO) {
return@withContext file.readText()
}
}Combining withContext and return can make your code less readable.
With suspend-kontext, you can simplify this code by using annotations:
@IOContext
suspend fun loadText(file: File): String {
return file.readText()
}This approach makes your code more concise and improves readability by explicitly defining the coroutine context at the function level.
You can use @IOContext, @DefaultContext, @MainContext, and @UnconfinedContext for now.
repositories {
mavenCentral()
}
plugins {
id("com.kitakkun.suspend-kontext") version "<version>"
}suspend-kontext is a Kotlin Compiler Plugin that allows you to specify the default coroutine context for suspending functions using annotations.
Switching coroutine contexts typically requires the use of withContext, like this:
suspend fun loadText(file: File): String {
return withContext(Dispatchers.IO) {
return@withContext file.readText()
}
}Combining withContext and return can make your code less readable.
With suspend-kontext, you can simplify this code by using annotations:
@IOContext
suspend fun loadText(file: File): String {
return file.readText()
}This approach makes your code more concise and improves readability by explicitly defining the coroutine context at the function level.
You can use @IOContext, @DefaultContext, @MainContext, and @UnconfinedContext for now.
repositories {
mavenCentral()
}
plugins {
id("com.kitakkun.suspend-kontext") version "<version>"
}