Created
May 20, 2018 05:50
-
-
Save kmshack/f3f7b5126925d6aca03cc322e9ac7ec2 to your computer and use it in GitHub Desktop.
coroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public actual fun launch( | |
context: CoroutineContext = DefaultDispatcher, | |
start: CoroutineStart = CoroutineStart.DEFAULT, | |
parent: Job? = null, | |
block: suspend CoroutineScope.() -> Unit | |
): Job { | |
val newContext = newCoroutineContext(context, parent) | |
val coroutine = if (start.isLazy) | |
LazyStandaloneCoroutine(newContext, block) else | |
StandaloneCoroutine(newContext, active = true) | |
coroutine.start(start, coroutine, block) | |
return coroutine | |
} | |
public actual fun <T> async( | |
context: CoroutineContext = DefaultDispatcher, | |
start: CoroutineStart = CoroutineStart.DEFAULT, | |
parent: Job? = null, | |
block: suspend CoroutineScope.() -> T | |
): Deferred<T> { | |
val newContext = newCoroutineContext(context, parent) | |
val coroutine = if (start.isLazy) | |
LazyDeferredCoroutine(newContext, block) else | |
DeferredCoroutine<T>(newContext, active = true) | |
coroutine.start(start, coroutine, block) | |
return coroutine | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment