Daniele B
06/16/2021, 9:09 AMsuspend fun getMyObject() : MyObject {
...
return myObject
}
val myApp = myCallback { myObject ->
/* code using myObject */
}
how should I write the function myCallback
?ursus
06/16/2021, 10:36 AMTim Malseed
06/17/2021, 3:03 AMsamuel
06/17/2021, 7:58 PMpy
06/17/2021, 10:15 PMzak.taccardi
06/18/2021, 3:50 AM1.5.0
of the lib), which means all Android projects that consume it must enable Java 8 desugaring?Mark Allanson
06/18/2021, 7:51 AMsupervisorScope
using async
. What is the most efficient way to await for the first failure of any of the jobs? At the moment I am looping the jobs, saving away successes, and capturing the first failure, then when that happens issuing a "controlled cancellation on the others" and using a yield (or delay) inside the tight loop, but it feels like there must be a better way of doing thistheapache64
06/18/2021, 10:07 AMsuspend
method in Java class. What's the correct way to do it?
SO Thread: https://stackoverflow.com/questions/68032757/how-can-i-implement-kotlin-suspend-method-in-a-java-classmkrussel
06/18/2021, 3:21 PMHowever, it is known to leak memory in scenarios involving concurrency under load, for example when multiple children coroutines running in different threads are simultaneously cancelled.
Would multiple jobs launched like the above roughly at the same time, produce the leak.Tiago Nunes
06/18/2021, 4:20 PMrunBlocking
, GlobalScope
, or what? I've tried kotlinx-coroutines-test, to use runBlockingTest
, but apparently this library is only for JVM?SrSouza
06/18/2021, 7:35 PMrunBlocking
?okarm
06/20/2021, 9:01 AMDispatchers.Default
fail to terminate the program and it was reported in November
https://github.com/Kotlin/kotlinx.coroutines/issues/2398Cody Mikol
06/21/2021, 6:04 PMfrankelot
06/21/2021, 7:32 PMsend
something to an actor and “suspend” until the message was processed?Sourabh Rawat
06/22/2021, 7:00 PMlhwdev
06/23/2021, 5:30 AMcoroutineScope
that will be cancelled if other things in it are completed? Normally tasks running in launch
in it will cause coroutineScope
not to return.Patrik Åkerfeldt
06/23/2021, 2:32 PMwithTimeout
to trigger an exception after 5 seconds of no response?Pablo Schmid
06/23/2021, 4:38 PMimport kotlinx.coroutines.*
import kotlin.system.*
fun main() = runBlocking {
val time = measureTimeMillis {
println("The answer is ${concurrentSum()} en ${Thread.currentThread()}")
}
println("Completed in $time ms en ${Thread.currentThread()}")
}
suspend fun concurrentSum(): Int = coroutineScope {
val one = async { doSomethingUsefulOne() }
val two = async { doSomethingUsefulTwo() }
one.await() + two.await()
}
suspend fun doSomethingUsefulOne(): Int {
println("1 in Thread ${Thread.currentThread()}")
delay(2000L) // pretend we are doing something useful here
return 13
}
suspend fun doSomethingUsefulTwo(): Int {
println("2 in Thread ${Thread.currentThread()}")
delay(2000L) // pretend we are doing something useful here, too
return 29
}
Paul Woitaschek
06/23/2021, 4:46 PMAbhishek Dewan
06/23/2021, 5:41 PMandroidexpertmanish
06/24/2021, 4:32 AMobobo
06/24/2021, 6:06 PMflow{}
builder, can I somehow guarantee that the code in the flow{}
will run inside a specific dispatcher but the code that collects the results sent by `emit()`will run in a less-restricted dispatcher?Ahaisting
06/24/2021, 8:03 PMcombine
behavior that I don’t expect, hoping someone can help me shed some light. (putting code snippet in thread)Rak
06/25/2021, 4:56 AMjulioromano
06/25/2021, 8:51 AMsuspend fun myFunction(myParam: String): Unit = myScope.launch {
doSomethingElseSuspending()
withContext(anotherContext) { doSomeOtherStuffInTheOtherContext(myParam) }
}.join()
The rationale is that the caller of myFunction
should not care of what’s happening inside it, the caller merely calls a suspending function (myFunction()
) that suspends until all work done inside it is done and then either throws or returns Unit.William Reed
06/25/2021, 5:58 PMsuspend fun
and wait for the result. however i am calling multiple `suspend fun`s from throughout my code base. I’m trying to think of a way to group these together and allow them to queue since each of the call sites uses a separate context/scope. another requirement is that if a particular command completes, it can cancel all remaining commands that are queued up. my first attempt at it in the thread -->Alejo
06/27/2021, 2:23 PMval userInteracting = MutableSharedFlow<Unit>(replay = 0)
onEvent(){
coroutineScope.launch {
userInteracting.emit(Unit)
}
}
coroutineScope.launch {
userInteracting.collectLatest {
showSky.value = false
delay(5000)
showSky.value = true
}
}
bloodshura
06/27/2021, 4:12 PMList#sortedWith
that takes a comparator which can be suspended?
Suppose I'd need something like this:
someList.sortedWith { o1, o2 -> suspendedComparison(o1, o2) }
Where suspendedComparison
is a function which returns Int
(satisfying Comparator
) and is a suspend fun
...Sudhir Singh Khanger
06/28/2021, 2:13 PMRetrofit
call without suspend keyword from a Coroutine
?Justin Tullgren
06/29/2021, 7:22 PMJustin Tullgren
06/29/2021, 7:22 PM