gildor
09/21/2018, 10:43 AMmuralimohan962
09/21/2018, 11:47 AMZach Klippenstein (he/him) [MOD]
09/21/2018, 1:06 PMapi-review
branch hasn't been merged yet, but i noticed this commit deprecates the onCompletion
parameters to launch, async, etc. What's the best way to wire up channels to cancel on coroutine completion after this change? Explicit try/catch in the coroutine? (Is there a discussion about this change anywhere I could read up on?)
https://github.com/Kotlin/kotlinx.coroutines/commit/3049652ff5e3a23e35bcc82e28fb87936ed836ecigorvd
09/21/2018, 1:45 PMreturn
line on my second suspend function, but it never return to the first one...jw
09/21/2018, 8:59 PMspierce7
09/22/2018, 3:58 AMlittlelightcz
09/22/2018, 9:49 AMio {}
pool as well (in some github discussions), so I am just re-throwing this idea again before the release decisions will be final (if they're not already) 🙂 .Nikky
09/22/2018, 10:27 PMNikky
09/23/2018, 12:27 AMvaskir
09/23/2018, 10:39 AMcoroutineScope {
(1..30)
.map {
async {
print("offering $it...")
queue.offer(it).await()
println("offered $it")
}
}.awaitAll()
}
Nikky
09/23/2018, 6:47 PMgotoOla
09/23/2018, 6:53 PMotakusenpai
09/24/2018, 5:12 AMDominaezzz
09/24/2018, 1:08 PMrunBlocking
in the standard library? Since you can suspend without kotlinx.coroutines, shouldn't you be able to at least block without it?gildor
09/24/2018, 2:44 PMspand
09/25/2018, 12:17 PMsynchronized(lock){
implicitScope.launch {
delay(1)
}
}
I get an error that says: " The 'delay' suspension point is inside a critical section". Seems safe to me ?spand
09/25/2018, 12:23 PMSuccessOrFailure
. I thought that had been renamed?darych
09/25/2018, 3:10 PMredrield
09/25/2018, 7:07 PMkirillrakhman
09/26/2018, 12:46 PMFragment
which implements CoroutineScope
. The default cancellation behavior is to cancel in onDestroy
. But one specific coroutine I want to cancel on a different event, e.g. in onDetach
. Should I create a nested scope or should I just manually cancel the coroutine when the event happens?elizarov
09/26/2018, 8:56 PMkotlinx-coroutines
version 0.27.0
is published — polishing structured concurrency, getting ready for release, fixing bugs, see for details https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.27.0nwh
09/26/2018, 9:15 PMenleur
09/26/2018, 9:16 PMcurrentScope
is deprecated now. How should we run launch inside suspend fun
now? Something like this CoroutineScope(coroutineContext).launch { }
?rdhruva
09/26/2018, 9:54 PMlouiscad
09/26/2018, 9:54 PMcurrentScope { }
is deprecated, should I use its implementation, CoroutineScope(coroutineContext)
instead?
I have some code relying on it:
suspend inline fun <E> ReceiveChannel<E>.doOnEach(
context: CoroutineContext = EmptyCoroutineContext,
noinline action: suspend (E) -> Unit
) = currentScope {
launch(context) { consumeEach { action(it) } }
}
that would become:
suspend inline fun <E> ReceiveChannel<E>.doOnEach(
context: CoroutineContext = EmptyCoroutineContext,
noinline action: suspend (E) -> Unit
) = CoroutineScope(coroutineContext).launch(context) { consumeEach { action(it) } }
gildor
09/27/2018, 5:30 AMgildor
09/27/2018, 5:32 AMMartin Devillers
09/27/2018, 8:19 AMDeferredCache
with an await
method which when called:
- if no coroutine to load the resource has been launched, it starts a new one
- if a coroutine to load the resource has finished successfully, it returns its result
- if a coroutine to load the the resource has finished with an error, it restarts a new one
- if a coroutine to load the resource has been launched and is still active, it awaits its result
My current implementation looks like this
class DeferredCache<T: Any>(
private val coroutineScope: CoroutineScope = GlobalScope,
private val block: suspend CoroutineScope.() -> T
) {
private var deferredValue: Deferred<T>? = null
private val deferredValueLock = Mutex()
private val usableDeferredValue: Deferred<T>?
get() = deferredValue?.takeUnless { it.isCompletedExceptionally }
suspend fun await(): T {
val deferredValue = usableDeferredValue ?: deferredValueLock.withLock {
usableDeferredValue ?: coroutineScope.async(NonCancellable, block = block).also { deferredValue = it }
}
return deferredValue.await()
}
}
Can you think of a more optimal solution? Anyone running into this scenario as well? Might it be worth adding a “standard” way to do this?aaverin
09/27/2018, 1:37 PMnerses
09/27/2018, 2:51 PMThe main difference between runBlocking and coroutineScope is that the latter does not block the current thread while waiting for all children to complete.But when i run the example there the nested launch inside
coroutineScope
blocks the execution of the runblocking
scope and the last println("Coroutine scope is over")
is always printed the last.
Am i getting it wrong? Or there is a mistake in the docs