rocketraman
11/17/2018, 4:03 PM"DefaultDispatcher-worker-5" - Thread t@95
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <1c724d56> (a sun.nio.ch.Util$3)
- locked <2daa5d57> (a java.util.Collections$UnmodifiableSet)
- locked <69cba374> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.selectNow(SelectorImpl.java:105)
at io.ktor.network.selector.ActorSelectorManager.process(ActorSelectorManager.kt:76)
at io.ktor.network.selector.ActorSelectorManager$process$1.invokeSuspend(ActorSelectorManager.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask$DefaultImpls.run(Dispatched.kt:235)
at kotlinx.coroutines.DispatchedContinuation.run(Dispatched.kt:81)
at kotlinx.coroutines.scheduling.Task.run(Tasks.kt:94)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:732)
Locked ownable synchronizers:
- None
"DefaultDispatcher-worker-5" - Thread t@78
java.lang.Thread.State: TIMED_WAITING
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:338)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.doPark(CoroutineScheduler.kt:835)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.cpuWorkerIdle(CoroutineScheduler.kt:813)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:721)
Locked ownable synchronizers:
- None
It isn't executing any application code, just continuously parking/unparking, AFAICT. How can I tell what is going on here and why this has happened?MrNiamh
11/17/2018, 4:13 PMigor.wojda
11/18/2018, 2:58 PMView1 calls repos.getData() - start downloading data
View2 calls repos.getData() - data download in progress so just wait for result
View2 calls repos.getData() - data download in progress so just wait for result
How this can be achieved?Massimo Carli
11/18/2018, 11:29 PMisClosedForReceive
has more chances to be updated and stop the cycle, otherwise, it won't and I get an exception. Basically, there's a race condition on the isClosedForReceive
property that doesn't allow me to use it as a condition for stop receiving. while (!kotlinChannel.isClosedForReceive) {
val data = kotlinChannel.receive()
delay(1) // NEEDED IN ORDER TO UPDATE (most of the time) isClosedForReceive
println(data)
}
Icaro Temponi
11/19/2018, 7:43 PMsuspend fun suspendCoroutineWithoutReturn(fn: (Continuation<Unit>) -> Unit) = suspendCoroutine(fn)
I was able to get exactly what i wanted:
suspend fun <T : AppCompatActivity> T.awaitRunOnUi(fn: T.() -> Unit) {
suspendCoroutineWithoutReturn { continuation ->
runOnUiThread {
fn()
continuation.resume()
}
}
}
Olekss
11/20/2018, 10:53 AMrocketraman
11/20/2018, 2:03 PMByteReadChannel.lookAheadSuspend
in which I was able to call consumeEachRemaining
, like this:
fun CoroutineScope.flowableOf(byteReadChannel: ByteReadChannel): Flowable<ByteBuffer> = rxFlowable {
byteReadChannel.lookAheadSuspend {
consumeEachRemaining {
send(it.copy())
true
}
}
}
In kotlinx-coroutines-io 0.1.0, this same code compiles but does not work -- it does not read the entire channel. Neither does the corresponding non-suspending lookAhead
method work.bdawg.io
11/20/2018, 9:46 PMval rootJob = Job()
val rootContext = Dispatchers.Default + rootJob
val otherJob = Job()
val otherScope = object : CoroutineScope {
override val coroutineContext = rootContext + otherJob
}
otherScope.doSomethingAsync()
otherScope.doSomethingElseAsync()
rootJob.cancel() // will this cancel items from otherJob?
bdawg.io
11/20/2018, 11:02 PMJob
that can be created similar to fun Job(parent: Job? = null)
where cancelsParent = false
Joris PZ
11/21/2018, 7:11 AMsuspend fun functionA() {
// A1
functionB()
// A2
}
suspend fun functionB() {
// B1
delay(1000)
// B2
}
where A1
, A2
etc denote normal, non-suspending code blocks. I'm trying to understand how these code blocks are scheduled on the available threads.
Suppose functionA
is currently executing on some thread T1
, using a dispatcher that has multiple threads available. The call to functionB
is a suspension point - is it correct to say that at that point, executing of my code may be suspended to allow some other work to be done on T1
? In that case, does that also mean that B1
can be scheduled on a different thread?
I'm pretty sure this happens around the call to delay
, but I'm uncertain about my own code.
Similarly, what about B2
and A2
? Are they guaranteed to be executed on the same thread, or is exiting a suspending function also a suspend point?goldin
11/21/2018, 8:07 AMElisabet Svensson Duranovic
11/21/2018, 12:22 PMJonathan
11/21/2018, 1:38 PMSaša Šijak
11/21/2018, 3:33 PMAlbert
11/21/2018, 7:44 PMchannel.take(10)
and there are currently only 8 elements, I want to have those 8 elements instead of waiting until it hits 10jw
11/22/2018, 2:36 AMasad.awadia
11/22/2018, 2:48 AMasad.awadia
11/22/2018, 2:54 AMjulioyg
11/22/2018, 3:20 PMDispatchers.Main
dispatcher, or do I need to mock that guy? I'm getting java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize
louiscad
11/22/2018, 3:26 PMasync
(and launch
) block in an actor
will close the actor
and make it stop accepting anything?dave08
11/22/2018, 8:06 PMdave08
11/22/2018, 8:32 PMlaunchInScope
function to do the same thing... just wondering if that's really the intention. If so, why not just abstract away the whole Job concept and let the end user deal only with scopes?Jonathan
11/23/2018, 10:13 AMExperimentalCoroutinesApi
when using maven? (the following is obviously not working)
<configuration>
<args>
<args>-Xuse-experimental=kotlin.Experimental</args>
<args>-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi</args>
<args>-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi</args>
</args>
</configuration>
leosan
11/23/2018, 12:46 PMCase: I have to fetch from api (if fails)> from cache (if fails) -> catrastrophic failure handling
So first case would be something like
Using lambdas
fun getContent(){
launch{
try{
val content =useCase.getContent(errorLambdaCallback= {handleError(it)})
showContent(content)
} catch(e:Exception){
handleError(e)
}
}
}
Or use channels to communicate back that some error happened but the cache is retrieved?
or there is actually a better way to handle this case where I need to handle error and get the contentuhe
11/23/2018, 2:25 PMproduce
has been started.
Is it possible to avoid this race?myanmarking
11/23/2018, 3:28 PMsomeFunctionThatCrash
Can any1 explain this behavior to me please?zak.taccardi
11/23/2018, 7:01 PMTolriq
11/23/2018, 8:41 PMsuspend fun fetchCharacterData(): CharacterGenerator.CharacterData = {
val apiData = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { URL(CHARACTER_DATA_ENDPOINT).readText()}
CharacterGenerator.fromApiData(apiData)
}
to start on good bases.Tolriq
11/24/2018, 10:16 AMSam
11/24/2018, 5:04 PMSam
11/24/2018, 5:04 PMDominaezzz
11/24/2018, 5:16 PMrunBlocking
to block the calling thread until all the `launch`ed child coroutines finish?Sam
11/24/2018, 5:44 PMrunBlocking {
launch {
delay( 200 )
println( "first launch done" )
}
launch {
delay( 100 )
println( "second launch done" )
}
}
Dominaezzz
11/24/2018, 5:45 PMlaunch
to finish before the second launch
?Sam
11/24/2018, 5:45 PMbdawg.io
11/24/2018, 5:47 PMDominaezzz
11/24/2018, 5:47 PMSam
11/24/2018, 5:48 PMbdawg.io
11/24/2018, 5:48 PMlaunch
is just overhead at this pointSam
11/24/2018, 5:50 PMrepeat( 1000 ) {
runBlocking {
launch {
println( "first launch done" )
}
launch {
println( "second launch done" )
}
}
}
Dominaezzz
11/24/2018, 5:51 PMSam
11/24/2018, 5:54 PMrepeat( 10 ) {
GlobalScope.launch {
launch {
println( "first launch done" )
}
launch {
println( "second launch done" )
}
}
Thread.sleep (100 )
}
runBlocking {
launch {
var sum = 0
repeat( 100_000_0000 ) {
sum += 1
}
println( "first launch sum $sum" )
}
launch {
var sum = 0
repeat( 10 ) {
sum += 1
}
println( "second launch sum $sum" )
}
}
Dominaezzz
11/24/2018, 6:44 PMSam
11/24/2018, 6:49 PMrunBlocking {
launch {
val time = measureTimeMillis {
BigInteger(3500, Random()).nextProbablePrime()
}
println( "first launch sum $time" )
}
launch {
println( "second launch sum" )
}
}
bdawg.io
11/24/2018, 7:20 PMrunBlocking(Dispatchers.Default) { ... }
?Sam
11/24/2018, 7:23 PMbdawg.io
11/24/2018, 7:24 PMGlobalScope.launch
will give you a different result because it uses Dispatchers.Default/CommonPool to obtain additional threads which allows more of your concurrent jobs to execute in parallel.Sam
11/24/2018, 7:25 PMbdawg.io
11/24/2018, 7:28 PMrunBlocking
by itself, it only has the current thread, so your first launch goes first on that single thread until it completes or suspends (which is why your 1 billion sum completes before the second starts), there's no additional threads for the second job to go in parallelSam
11/24/2018, 7:30 PMbdawg.io
11/24/2018, 7:37 PMSam
11/24/2018, 7:38 PMDaniel Tam
11/25/2018, 10:16 AMjoin
on itpankajrai
11/25/2018, 12:15 PMbdawg.io
11/25/2018, 10:25 PMrunBlocking