Cody Mikol
04/02/2021, 4:35 PMrunBlocking {
val (foo,bar) = doAsync({ foo() },{ bar() })
val (baz,bax) = doAsync({ baz(foo) },{ bax(bar) })
return listOf(foo,bar,baz,bax)
}
Assuming doAsync runs the inner lambdas concurrently, would runBlocking the outer scope force these to run synchronously ?Deepak Gahlot
04/05/2021, 11:46 AMJiri Malina
04/05/2021, 1:49 PMawaitClose
on CallbackFlow
? (details in thread)vkholyavin
04/05/2021, 3:47 PMvineethraj49
04/05/2021, 5:42 PMSpiral123
04/05/2021, 9:30 PMBig Chungus
04/06/2021, 1:43 PMDariusz Kuc
04/06/2021, 2:10 PMchannelFlow
? e.g.
flowOf(1, 2, 3).map {
id -> coroutineScope {
val first = async { retrieve(id) }
val second = async { retrieveOther(id) }
first.await() + second.await()
}
}
knthmn
04/07/2021, 3:31 AMinterface Foo {
fun flowValue(): Flow<Value> // flow the stored value
suspend fun setValue(value: Value) // update the stored value
}
however the implementation is not for me to control, and sometimes flowValue()
sometimes emit the old value several times before emitting the set value. What is the best way to test this?darkmoon_uk
04/07/2021, 8:35 AMFlow
setup) forms a circular reference.
In these cases, it's impossible to declare all parts of an overall Flow linearly; at some point we need to reference a part that hasn't been declared yet.
In RxJava the idiomatic way to work around this was using Relay
- a specialised Subject
.
Is there a Flow
equivalent?
It seems that a MutableSharedFlow
with replay = 0
will have the right semantics.niqo01
04/08/2021, 3:06 AMretry
based on a valid emitted value and not based on exception occuring?
My emitted value looks like this
public sealed class BillingClientState{
public object Initializing: BillingClientState()
public data class Available(val client: BillingClient): BillingClientState()
public object Unavailable: BillingClientState()
public object Disconnected: BillingClientState()
}
I want rety when Disconnected is triggeredtkez
04/08/2021, 11:08 AMprivate val job = SupervisorJob()
private val scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO> + job)
Simon Lin
04/09/2021, 2:13 AMNikola Milovic
04/09/2021, 9:01 AMfun A() {
B()
C()
}
fun B(){
scope.launch{
//call some suspending fun
}
}
So now C will be executed before B finishes even tho B isn't suspending fun?genovich
04/10/2021, 5:25 PMDeferred
in select
when the first one returns value?
select {
deferred1.onAwait { it }
deferred2.onAwait { it }
}
natario1
04/11/2021, 10:47 AMSharingStarted.WhileSubscribed()
with the extra feature that if the flow has never emitted, wait for first emission before stopping? In other words, if someone subscribes but then leaves before receiving the first value, wait for it before stop.
Looking at source code it seems quite easy to modify WhileSubscribed
to do this (just add sharedFlow.first()). But we don't have the SharedFlow when creating SharingStarted
, we only have the upstream flow which means that values in the replay cache are ignored.Nate Emmons
04/12/2021, 2:27 AMdelay
back to the client websocket coroutines relatively frequently to look for new inputnatario1
04/12/2021, 10:34 AMkotlinx.coroutines.debug
and the debugger in Android Studio has no "Coroutines" tab.Daniele B
04/12/2021, 12:58 PMval scope1 = CoroutineScope(Job() + "myscope")
val job1 = scope1.launch { … }
val scope2 = CoroutineScope(Job() + "myscope")
val job2 = scope2.launch { … }
Are “scope1" and “scope2” actually the same scope, or are they different?Jrichards1408
04/12/2021, 1:29 PMvineethraj49
04/13/2021, 3:37 AMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
onto a new thread?
applies to GlobalScope.future(<http://Dispatchers.IO|Dispatchers.IO>)
etc as welluli
04/13/2021, 3:39 PMprivate suspend fun <T> (suspend () -> T).foo()
and
private suspend fun <T> bar(lambda: suspend () -> T)
I need to explicitly write suspend { delay(1) }.foo()
but it’s fine to just call bar { delay(1) }
without suspend keywordrook
04/13/2021, 4:19 PMinvokeOnCompletion
. Given the following
launch(Dispatchers.Default) {
val theJob = async(<http://Dispatchers.IO|Dispatchers.IO>) {}
// do some work
theJob.invokeOnCompletion { println() }
}
If do some work
takes longer than theJob
to complete, the handler block runs on Dispatchers.Default
, whereas if theJob
takes longer than do some work
, the handler block runs on <http://Dispatchers.IO|Dispatchers.IO>
.Steffen Funke
04/14/2021, 8:40 AMdoOnNext
operators for side-effects, like printing, etc. What is the equivalent in Kotlin Flows? AFAIK, onEach
consumes the flow, and would not be appropriate there. Or am I missing something?Peter
04/14/2021, 7:15 PMCancellableContinuationImpl
would have such a large retained size?spand
04/15/2021, 6:19 AMclass SuspendAtomicRef<T : Any> {
private var data: T? = null
private val mutex = Mutex()
suspend fun getOrSet(init: suspend () -> T): T {
return mutex.withLock {
data ?: init().also { data = it }
}
}
}
Seems pretty basic so I wonder if I am missing it in the coroutines library?Chris Grigg
04/15/2021, 1:56 PMcollect
on a SharedFlow and then call delay
within the collect’s body, will it block other subscribers from retrieving emitted messages? My expectation is that it will because my understanding of flows is that they distribute messages synchronously through subscribers.Andrew Ebling
04/15/2021, 3:40 PMsuspend
functions in Android (which get triggered from non-UI events) and you suddenly find you need a Context
to get something done (in this instance load a preference value), what are sound approaches to adopt? I understand that storing Context
references is a no-no, due to the potential to leak Activites.bod
04/15/2021, 7:51 PMsuspend fun main()
, the program doesn't exit at the end of the main
. It's not big deal since I can of course manually end it with exitProcess(0)
but I'm wondering if I'm doing something wrong, or is this normal?rocketraman
04/17/2021, 12:35 AMflow.transformLatest { value ->
while(currentCoroutineContext().isActive) {
emit(value)
delay(x)
}
}
rocketraman
04/17/2021, 12:35 AMflow.transformLatest { value ->
while(currentCoroutineContext().isActive) {
emit(value)
delay(x)
}
}
Steffen Funke
04/17/2021, 7:35 AMcombine
a timer (for the "periodical every x seconds part"), and my actual flow, like this:
// the timer
val timer = (0..Int.MAX_VALUE).asSequence().asFlow().onEach { delay(1_000) }
// your other flow
val other = flow {
emit("A")
delay(1500L)
emit("B")
delay(1500L)
emit("C")
}
// combine them
launch {
combine(timer, other, ::Pair)
.collect { (timer, other) ->
println("bling: ${timer} | ${other}")
}
}
rocketraman
04/17/2021, 5:54 PMokarm
04/20/2021, 10:53 PMrocketraman
04/20/2021, 10:55 PMtransformLatest
approach?okarm
04/20/2021, 11:08 PM