Icaro Temponi
07/30/2019, 7:27 PMKulwinder Singh
07/31/2019, 6:51 AMdelay
execution for random time between 5-9 mins,
So what is best way to do it with kotlin in android ? Simply using delay
or flows/channels
?adeln
07/31/2019, 7:50 AMfun <T> List<Deferred<T>>.toFlow(): Flow<T>
I want the flow to emit values as soon as they become availableadeln
07/31/2019, 9:25 AMcallbackFlow
just calls channelFlow
🙂Paul N
07/31/2019, 11:20 AMval output = mutableListOf<String>()
for (something in channel) {
if (some condition based on something) {
output.add(something)
}
}
ursus
07/31/2019, 3:09 PMIcaro Temponi
07/31/2019, 5:49 PMflow()
.conflate()
.buffer(1)
.onEach { updateNotifications() }
.launchIn(GlobalScope)
Lorenzo Testa
08/01/2019, 11:34 AMhalim
08/01/2019, 2:34 PMrunBlocking {
println("start main")
execute(coroutineContext) { println("some long operation") }
println("main done")
}
fun execute(context: CorouitneContext, action: suspend () -> Unit) {
action.startCorouitne(Continuation(context + <http://Dispatchers.IO|Dispatchers.IO>) {
println("corouitne complete")
})
}
so when execute :
start main
main done, i expected to see : corouitne complete
"startCorouitne" start a new coroutine in my case i bound it to runBlocking scope (with context as parent) and with dispather IO, so i expect to see "coroutine complete" in console ??
i think this new coroutne created by startCoroutine its not bound to runBlocking so when main is finish its ignore this corouitnezak.taccardi
08/01/2019, 3:50 PMFlow<T>
support multicasting yet?Aslam Hossin
08/01/2019, 4:20 PMgroostav
08/01/2019, 7:31 PMLuis Munoz
08/01/2019, 8:25 PMMarko Mitic
08/01/2019, 9:17 PMsynchonized
block. Here's the test, results in thread
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.yield
class Test {
var i = 0
suspend fun countWithThreadSwitching(){
repeat(10) {
i++
delay(1) //yield() didn't make coroutine resume on another thread
}
println(i)
}
}
fun main() = runBlocking {
coroutineScope{
repeat(100) {
launch(Dispatchers.Default) {
Test().countWithThreadSwitching()
}
}
}
}
ansman
08/02/2019, 1:06 PMsomeFlow
.conflate()
.broadcastIn(someScope)
.asFlow()
Aldo Wachyudi
08/03/2019, 2:49 AMyschimke
08/03/2019, 10:02 AMChainchelliah
08/03/2019, 7:17 PMthana
08/04/2019, 11:22 AMcoroutineContext
documentation "By convention, should contain an instance of a job to enforce structured concurrency.". What does it mean? It'spossible that a context does NOT contain a job? what are the consequences if a job instance is missing?bombe
08/04/2019, 4:14 PMAldo Wachyudi
08/05/2019, 2:39 AMcoroutineScope
or supervisorScope
. When should we use it instead of using CoroutineScope(SupervisorJob())
? How do we cancel coroutineScope
or supervisorScope
?Lorenzo Testa
08/05/2019, 10:42 AMClosedSendChannelException: Channel was closed
, can someone explain it to me?
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
@UseExperimental(ExperimentalCoroutinesApi::class)
fun main() = runBlocking {
val scope = CoroutineScope(Job())
val f = channelFlow {
launch(scope.coroutineContext) {
repeat(10) {
delay(200L)
send(it)
}
}
}
f.collect {
println(it)
}
delay(3000L)
}
Eric Martori
08/05/2019, 1:17 PMval flow get() = channel.asFlow()
private val channel =
BroadcastChannel<T>(???)
I want that each time a user of the API calls flow.collect{}
the last value is received on collect, but no values are lost if they are received in quick succession and the sender should suspend if needed for this to happen.
With CONFLATED
I get the last value emited on each new collect
and with BUFFERED
I get the "suspend if needed, don't loose any values" behaviour.
Is there a way to achieve what I want?v0ldem0rt
08/05/2019, 1:18 PMsuspend operator fun <T> invoke(block: suspend () -> T): T {
// ...
}
to work. Does invoke
work with suspend
keyword?aerb
08/05/2019, 5:29 PMtry
/ catch
oriented way of accessing the result of async
? Thinking of something similar to Result
rook
08/05/2019, 9:29 PMReceiveChannel
is coming back already closed from this signature
@ExperimentalCoroutinesApi
override fun CoroutineScope.messageUpdateProducer(): ReceiveChannel<List<Message>> = produce {
realm.where(RealmMessage::class.java).findAll().addChangeListener { results ->
offer(results.takeIf { it.isNotEmpty() }?.map { it.messageActual } ?: listOf())
}
}
It looks like, from the documentation that if the producer encounters an error, it will close automatically, but I’m not sure what’s generating an error in there. I’m handling all the null cases and my crashes are only generating a stack trace internal to the channel mechanism.
kotlinx.coroutines.channels.ClosedReceiveChannelException: Channel was closed
at kotlinx.coroutines.channels.Closed.getReceiveException(AbstractChannel.kt:1094)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveSelect.resumeReceiveClosed(AbstractChannel.kt:993)
at kotlinx.coroutines.channels.AbstractSendChannel.helpClose(AbstractChannel.kt:332)
at kotlinx.coroutines.channels.AbstractSendChannel.close(AbstractChannel.kt:271)
at kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(Channel.kt:95)
at kotlinx.coroutines.channels.ProducerCoroutine.onCompleted(Produce.kt:98)
at kotlinx.coroutines.channels.ProducerCoroutine.onCompleted(Produce.kt:91)
at kotlinx.coroutines.AbstractCoroutine.onCompletionInternal(AbstractCoroutine.kt:102)
at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.kt:274)
at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:784)
at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:764)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:111)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5223)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
ahulyk
08/06/2019, 10:16 AMDominaezzz
08/06/2019, 10:26 AMBroadcastChannel
but I'm not sure how to expose it. Should I literally expose the BroadcastChannel
for users to call openSubscription()
or should I wrap this up?Big Chungus
08/06/2019, 10:52 AMManuel Vivo
08/06/2019, 2:28 PMManuel Vivo
08/06/2019, 2:28 PMjw
08/06/2019, 2:30 PMManuel Vivo
08/06/2019, 2:32 PM