From a89003e61d02f4679488d1196b18b4f89afd4a7f Mon Sep 17 00:00:00 2001 From: Jieyi Date: Tue, 5 Mar 2019 14:32:23 +0900 Subject: [PATCH] Feature: added the coroutine changing. --- gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../src/main/java/com/devrapid/kotlinshaver/Coroutine.kt | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4c02a70..ef4edcd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=2.1.8 +proj_version=2.1.9 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -39,4 +39,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=1.1.8 +proj_kotlin_version=1.1.9 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 869980e..4701b85 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt index 68f8e1e..7abb323 100644 --- a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Coroutine.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -39,3 +40,11 @@ inline fun uiAsync(noinline block: suspend CoroutineScope.() -> T) = inline fun bkgAsync(noinline block: suspend CoroutineScope.() -> T) = CoroutineScope(Default).async(block = block) inline fun ioAsync(noinline block: suspend CoroutineScope.() -> T) = CoroutineScope(IO).async(block = block) + +// ----------------------- with context + +suspend fun uiSwitch(block: suspend CoroutineScope.() -> T) = withContext(Main.immediate, block) + +suspend fun bkgSwitch(block: suspend CoroutineScope.() -> T) = withContext(Default, block) + +suspend fun ioSwitch(block: suspend CoroutineScope.() -> T) = withContext(IO, block)