Skip to content

Instantly share code, notes, and snippets.

@user-mw
Created April 15, 2022 06:18
Show Gist options
  • Save user-mw/fb8b7615b9d322fb4f0e6605c034a0d1 to your computer and use it in GitHub Desktop.
Save user-mw/fb8b7615b9d322fb4f0e6605c034a0d1 to your computer and use it in GitHub Desktop.
Coroutines. async() inside
// Code
public fun <T> CoroutineScope.async(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> T
): Deferred<T> {
val newContext = newCoroutineContext(context)
val coroutine = if (start.isLazy)
LazyDeferredCoroutine(newContext, block) else
DeferredCoroutine<T>(newContext, active = true)
coroutine.start(start, coroutine, block)
return coroutine
}
// Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment