Skip to content

Commit

Permalink
Feature: added the coroutine changing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokk committed Mar 5, 2019
1 parent 9bbc35b commit a89003e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,4 +39,4 @@ [email protected]
proj_kotlin_name=kotlinshaver
proj_kotlin_libname=KotlinShaver
proj_kotlin_artifactid=kotlinshaver
proj_kotlin_version=1.1.8
proj_kotlin_version=1.1.9
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -39,3 +40,11 @@ inline fun <T> uiAsync(noinline block: suspend CoroutineScope.() -> T) =
inline fun <T> bkgAsync(noinline block: suspend CoroutineScope.() -> T) = CoroutineScope(Default).async(block = block)

inline fun <T> ioAsync(noinline block: suspend CoroutineScope.() -> T) = CoroutineScope(IO).async(block = block)

// ----------------------- with context

suspend fun <T> uiSwitch(block: suspend CoroutineScope.() -> T) = withContext(Main.immediate, block)

suspend fun <T> bkgSwitch(block: suspend CoroutineScope.() -> T) = withContext(Default, block)

suspend fun <T> ioSwitch(block: suspend CoroutineScope.() -> T) = withContext(IO, block)

0 comments on commit a89003e

Please sign in to comment.