Edoardo Luppi
03/27/2024, 10:44 AMlimitedParallelism
, and found that the int value is checked with
// Save a few bytecode ops
internal fun Int.checkParallelism() = require(this >= 1) { "Expected positive parallelism level, but got $this" }
Was this done because of bytecode size limitations of the Android platform? Or because of something else?groostav
03/28/2024, 12:08 AMclass kotlin.coroutines.jvm.internal.DebugProbesKt (in module kotlin.stdlib) cannot access class kotlinx.coroutines.debug.internal.DebugProbesImpl (in module kotlinx.coroutines.core) because module kotlin.stdlib does not read module kotlinx.coroutines.core
//edit: java 17, kotlin 1.9.23
Not sure what to do. Can i add-opens that from a module file or do i have to do it from the java invocation, or can i get it on the javac invocation?Colton Idle
03/29/2024, 4:53 AMfun checkSomethingAndUpdateState(){
viewModelScope.launch {
val abc = repo.getSomething()
updateState(abc)
}
}
Repo.getSomething() is simple because it uses a 3rd part library that's already "main safe"
suspend fun getSomething(){
val foo = thirdParty.getThing() <=== according to 3rd party docs, this happens on IO dispatcher, so its main safe
}
My question is whether or not my viewModelScope.launch() {} should pass in a dispatchers? I guess not right since all of the code it calls is main safe, and my only consideration is really "updating" the ui state, which is fine to happen on main thread (i.e. updateState)Edoardo Luppi
03/31/2024, 4:18 PMIllegalStateException
and error("...")
in the library, just to understand if there is a consensus in the official Kotlin libraries that I can use for my own libraries.
However, I see both are used. So I suppose it's a random decision at coding time.Leon Linhart
04/01/2024, 8:21 PMfun subscribe(...): Flow<...>
function.
Specifically, I'm struggling with and could use some tips/opinions on how to properly close the underlying IO resource (in this case, the websocket connection). (See 🧵)ursus
04/01/2024, 11:15 PMsqldelight
flow (on main thread). I want to see every emit.
Would adding a buffer
help?
(Since the default behavior is to suspend the source so every value can be collected)Norbi
04/04/2024, 4:35 PMPeter Farlow
04/05/2024, 6:17 AMABRAR WIRYAWAN
04/07/2024, 11:54 PMKlitos Kyriacou
04/09/2024, 8:34 AMMDC.put(some context...)
withContext(<http://Dispatchers.IO|Dispatchers.IO> + MDCContext()) {
...some asynchronous processing...
}
// At this point MDC is clear, the original context has disappeared!
After the withContext
call, the entries in the MDC have all been removed and the context map is empty. Does anyone have any clues how I can go about figuring out how/why/where this context is getting zapped?Matt Nelson
04/10/2024, 7:48 AMColton Idle
04/11/2024, 5:18 PMAbhimanyu
04/11/2024, 6:40 PMsuspend fun getData1(): DataModel1 { ... }
suspend fun getData1(): DataModel1 { ... }
suspend fun getData1(): DataModel1 { ... }
fun processData(
data1 : DataModel1,
data2 : DataModel2,
data3 : DataModel3,
): Boolean { ... }
I have a suspend method which uses all the above methods like this currently.
suspend fun usageMethod() {
coroutineScope {
val deferred = awaitAll(
async {
getData1()
},
async {
getData1()
},
async {
getData1()
},
)
processData(deferred[0], deferred[1], deferred[2])
}
}
This works as expected, but I am unable to return the Boolean
result of the processData()
from the usageMethod()
.
Note: I am using async to execute all the data fetching methods in parallel.Alexandru Hadăr
04/11/2024, 8:21 PMsuspend fun printId() {
val id = getId() // suspend fun getId(): String
saveId(id) // private suspend fun saveId(id: String)
println("Your id is: $id")
}
Roughly, translated by the compiler it would look like:
fun printId(continuation: Continuation<*>) {
val result : Result<Any>? = continuation.result
when (continuation.label) {
0 -> {
continuation.label = 1
val res = getId(continuation)
if (res == COROUTINE_SUSPENDED) {
return COROUTINE_SUSPENDED
}
result = Result.success(res)
}
1 -> {
...
}
}
}
What I don't understand is when will result = Result.success(res)
ever be called?
From what I can tell:
• label is already 1, so when the continuation's resumeWith
inside getUserId
will be called will go directly to 1
• otherwise, getId
could only return COROUTINE_SUSPENDED
, because will move the function to another thread;
Could it be when the we don't use a dispatcher inside getId
, so everything is on the same thread? Any other cases?CLOVIS
04/14/2024, 11:34 AMColton Idle
04/14/2024, 6:38 PMflow {}
builder because I need to be able to emit from anywhere in my class. Is "SharedFlow" essentially the way to go here, or what?CLOVIS
04/15/2024, 10:22 AMSebastian Lehrbaum
04/16/2024, 4:53 PMreline
04/18/2024, 4:41 PMval step3Channel = actor { /*processing..*/ println("finished!") }
val step2Channel = actor { /*processing..*/ step3Channel.send(result) }
val step1Channel = actor { /*processing..*/ step2Channel.send(result) }
This becomes cumbersome when the item passed to each channel has a lot of fields and there's no way to "short-circuit" and skip any of the steps.
Is there a better way of doing this?Troy Perales
04/19/2024, 1:20 AMvar
of type Job
to some “no-op” value to avoid having a nullable type?julioromano
04/19/2024, 8:47 AMsuspendCancellableCoroutine
does the order of the call to invokeOnCancellation
matter?
I mean, is it best to call invokeOnCancellation
as first thing inside the suspendCancellableCoroutine
lambda?
Or is it the same if it's called as last instruction?Marc
04/19/2024, 12:32 PMcoroutineScope {
select {
launch {
item.gatt.connectionState.first { it == GattConnectionState.STATE_DISCONNECTED }
}.onJoin { }
launch @SuppressLint("MissingPermission") {
while (isActive) {
try {
item.characteristic.splitWrite(item.data, writeType = BleWriteType.NO_RESPONSE)
break
} catch (e: Exception) {
delay(200.milliseconds)
}
}
}.onJoin { }
}
cancel()
}
My problem is that after one of the 2 select branches completes, the cancel()
call does nothing and the coroutineScope never completes, as it seems like the first()
call cannot be cancelled and the splitWrite()
call is also implemented using suspendCoroutine
and therefore also cannot be cancelled. How do I get around this issue?Arjan van Wieringen
04/19/2024, 2:16 PMsuspend { .... }
in any code now, without being in a suspending context. How does this work?louiscad
04/19/2024, 9:54 PMMarcin Wisniowski
04/22/2024, 9:03 AMTóth István Zoltán
04/23/2024, 4:54 AMreactormonk
04/23/2024, 3:08 PMFlow<A>
to create a transforming operation which stitches together multiple A
to create a single A
without using suspend
or a scope
?reactormonk
04/23/2024, 4:29 PMsuspend fun someFun(flow: Flow<A>): Unit {
withContext(Dispatchers.Default) {
launch {
flow.collect { }
}
}
}
return immediately?
So I did
suspend fun someFun(flow: Flow<A>): Unit {
println("0")
withContext(Dispatchers.Default) {
println("1")
launch {
println("2")
flow.collect { }
}
println("3")
}
println("4")
}
and got
0
1
3
2
WTF?Slackbot
04/23/2024, 5:14 PMreactormonk
04/23/2024, 5:25 PMclose()
a Channel
, do existing subscribers which haven't consumed all items in the channel still get all items which have been send()
to the channel in the past?