Joan Colmenero
10/19/2019, 1:05 PMJoan Colmenero
10/19/2019, 4:07 PMResultWrapperT
from CallT
but now reading this answer [1] from stackoverflow then I realized that if I'm using suspended fun
I do not have to add the CallT
so, how do I do the change now? I was using this method :
fun <reified T:Any> execute(function: () -> Call<T>): ResultWrapperT =
try {
when (T::class) {
Unit::class -> function().execute().let {
ResultWrapper.Success(Unit as T)
}
else -> function().execute().body()?.let {
ResultWrapper.Success(it)
} ?: ResultWrapper.Error(Exception("no body there"))
}
} catch (e: Exception) {
ResultWrapper.Exception(e)
}
Any idea? The problem now is that as it's not a CallT
I do not have the execute()
method...
[1] : https://stackoverflow.com/a/57810074/4329781poohbar
10/19/2019, 8:30 PMMani
10/20/2019, 9:12 AMval allWarehouses: List<Warehouse> = getWarehouses()
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
allWarehouses.forEach { warehouse ->
val notes = getNotes()
// I want to run this loop in parallel
notes.forEach {
serviceClient.markDone(note) // this is an IO call
}
}
}
I want to run the forEach operation in parallel. Is this the right way of doing?Mani
10/20/2019, 9:23 AMnotes.parallelStream().forEach { println(it) }
tapac
10/20/2019, 6:47 PMDeferred
interface? I was trying to delegate that interface to an instance returned by async
function, but it doesn't work well.
class MyDeferred<T>(val original: Deferred<T>) : Deferred<T> by original
MyDeferred(async{ ...} )
I want to be able to call some code on async completition or execption, maybe there is another way?Jayden
10/21/2019, 4:28 AMval events =
flowOf(
callbackFlow { }.map { SealedClass.Property1 },
callbackFlow { }.map { SealedClass.Property2 },
BroadcastChannel(1) .asFlow().map { SealedClass.Property3 }
).flattenMerge()
But, when I offer
to the broadcast channel nothing is emitted from events. The callback flows however, work fine.Robert Jaros
10/21/2019, 7:40 AM.flow().map { ... }.toList()
or
.flow().toList().map { ... }
Lewon.G
10/21/2019, 12:39 PMMatt Thiffault
10/21/2019, 7:55 PMJan Skrasek
10/22/2019, 12:25 PMSingleLiveData<T>
, e.g. something what observe value just once, but on multiple places (observers).stkent
10/22/2019, 2:15 PMLuke Rohde
10/22/2019, 2:19 PMticker
, but it’s marked as obsolete and it’s unclear whydavide
10/22/2019, 3:04 PMkevinherron
10/22/2019, 5:33 PMWorker.doPark
or WorkQueue.trySteal
. Is this… expected?Nikky
10/22/2019, 8:52 PMsuspend operator get(id: String)
and is there any way to use operator overloading with suspending functions ?napperley
10/23/2019, 1:19 AMjames
10/23/2019, 2:22 AMdebounce
to debounce text changes from an Android EditText? I've done this previously using RxJava but RxAndroid did the hard work there with RxTextView.textChanges
.. I'm wondering how I can achieve this in the world of coroutines/flowTuan Kiet
10/23/2019, 8:32 AMsuspendCancellableCoroutine { continuation ->
do we need to check anything like isActive or isCancelled
before call resumeWith
and why?Kulwinder Singh
10/23/2019, 12:43 PMcombine
in flows like below
Firestore.getFlow1().combine(Firestore.getFlow2()) { f1, f2 -> Result(f1,f2)}
.combine(Firestore.getFlow3()) { f3, result -> result.f3 = f3 }
.collect { _liveData.value = it}
Here Firesstore.get*
all are wrappers that converts firestores snapshow listeners to flow, so here i have to listen three flows and want to combine them . is it good to do like this or there is any other way also ?zak.taccardi
10/23/2019, 3:45 PMsdeleuze
10/24/2019, 12:11 PMEventSource
to a Flow
that emits the data received by the onmessage
callback ?Animesh Sahu
10/24/2019, 4:07 PMzak.taccardi
10/24/2019, 5:46 PMCoroutineScope
backed by a multi-thread dispatcher. I also have a Channel<Int>
that needs to receive incoming messages.
val scope = CoroutineScope(Dispatchers.Default)
val channel: Channel<Int> = TODO()
fun onNewInt launch`(newInt: Int) {
// `newInt` is delivered from outside a coroutine
// what is the appropriate way to emit to the channel?
}
I see two possibilities (see code snippet)zak.taccardi
10/24/2019, 10:21 PMFlow<Unit>
every 40 milliseconds?
old solution:
channelFlow<Unit> {
while (isActive) {
delay(40)
send(Unit)
}
}
new, better solution:
flow {
while (true) {
delay(40)
emit(Unit)
}
}
james
10/25/2019, 4:48 AMsuspend fun
from a java class with Java 7 compatibility? I found some information by googling on how to do this with Java 8+, but not Java 7ubu
10/25/2019, 11:30 AMoverride suspend fun createAccount(
name: String,
avatarPath: String?
) : AccountEntity {
Timber.d("Thread: ${Thread.currentThread().name}")
return service.createAccount(name, avatarPath).let { response ->
AccountEntity(
id = response.id,
name = response.name,
avatar = response.avatar.toEntity()
)
}
}
I launch inside ViewModelScope
. Any help will be appreciated!zak.taccardi
10/25/2019, 8:21 PMviewModelScope
being pushed by the Android team? It requires a bunch of workarounds that would be completely unnecessary if the CoroutineScope
was just injected into the ViewModel
Fudge
10/26/2019, 4:15 PMAdriano Celentano
10/27/2019, 12:28 PMsuspend fun test() {
suspendingFunctionScope.launch {
...
}
}
Adriano Celentano
10/27/2019, 12:28 PMsuspend fun test() {
suspendingFunctionScope.launch {
...
}
}
Fudge
10/27/2019, 12:35 PMtseisel
10/27/2019, 12:36 PMlaunch
call into a coroutineScope
block:
suspend fun test() = coroutineScope {
launch {
...
}
}
Note that the test
function will not return before the launched coroutine is completed. If that's not what you want, you should consider making test
a non-suspending extension of CoroutineScope
, which is the usual way to define a function that starts a coroutine:
fun CoroutineScope.test()
Adriano Celentano
10/27/2019, 12:48 PMclass GameEngine {
fun CoroutineScope.start() {
...
}
tseisel
10/27/2019, 1:06 PMval engine = GameEngine()
with(engine) {
scope.start()
}
This is because a member function can (normally) have only one receiver.
Something like fun startIn(scope: CoroutineScope)
would be better. You can also pass a CoroutineScope
as a constructor parameter of your engine, provided the engine has the same lifetime as the passed scope.Adriano Celentano
10/27/2019, 1:56 PM