jw
07/21/2018, 3:12 AMv0ldem0rt
07/21/2018, 9:36 PMgroostav
07/23/2018, 7:51 AMselect {}
will simply abandon your coroutine?
@Test fun `using an empty select clause just abandons you`() = runBlocking {
val producer = produce<String> {
select<String> {
val x = 4;
}
val y = 4;
}
val result = producer.receiveOrNull()
val z = 4;
}
never completesv0ldem0rt
07/23/2018, 3:38 PMnewFixedThreadPoolContext
then will coroutines jump between threads like Unconfined
?rocketraman
07/23/2018, 6:25 PMdoResume
within a class without a line number e.g. at com.MyClass$withFoo$1.doResume(MyClass.kt) ~[classes/:?]
groostav
07/25/2018, 6:28 AMbj0
07/25/2018, 11:23 PMwinteryoung
07/26/2018, 1:03 PMcont.initCancellability()
should be placed after removeXXX
. Because if the coroutine was cancelled right after the init call, the waiter won't be removed.dharrigan
07/26/2018, 6:58 PMkevinherron
07/27/2018, 3:36 AMgildor
07/27/2018, 6:13 AMuhe
07/27/2018, 2:25 PMjava.lang.RuntimeException: Method myLooper in android.os.Looper not mocked. See <http://g.co/androidstudio/not-mocked> for details.
at android.os.Looper.myLooper(Looper.java)
at kotlinx.coroutines.experimental.android.MainLooperChecker.checkRunBlocking(HandlerContext.kt:124)
The tests are plain JVM unit tests and use runBlocking
to test presenterswakingrufus
07/27/2018, 8:10 PMasync {
while(isActive){
....
}
return "something"
}
how can I cancel it so that I can call await
without getting a cancellation exception?spierce7
07/27/2018, 10:22 PMdharrigan
07/28/2018, 2:13 PMsvenjacobs
07/30/2018, 11:38 AMConflatedBroadcastChannel
which keeps the last sent item and delivers it to new subscribers in openSubscription()
. I'm looking for an event bus implementation that does not cache items. So if an event is send but there are no active subscriptions the bus should just drop the event. Unfortunately there doesn't seem to be a default implementation of BroadcastChannel
with these characteristics. Has anyone an idea how to implement a simple non-caching event bus?rdhruva
07/30/2018, 5:12 PMCoroutineContext
?
Context: In my android app, I have a “god” object that handles all the network api calls and responses (using callbacks), and has its own lifecycle of sorts: I’m trying to write a CoroutineContext
that will allow me to write coroutines that dispatch to the DefaultDispatcher
but are aware of the lifecycle of this god objectJonathan Walsh
07/31/2018, 5:07 PMasCompletableFuture
. It seems to hang if my coroutine throws an exception.
class CompletableFutureTest {
@Test
fun testFailAsCompletableFuture() {
val executeJob = async {
fail("Test failed predictably")
}
val future = executeJob.asCompletableFuture()
println("### asCompletableFuture")
future.get()
println("### Execute job completed!")
}
}
I get this stacktrace in the log
Exception in thread "ForkJoinPool.commonPool-worker-1 @coroutine#1" kotlinx.coroutines.experimental.CompletionHandlerException: Exception in completion handler InvokeOnCompletion[InvokeOnCompletion@377acc75] for "coroutine#1":DeferredCoroutine{CompletedExceptionally}@685fc50a
at kotlinx.coroutines.experimental.JobSupport.completeUpdateState(JobSupport.kt:226)
at kotlinx.coroutines.experimental.JobSupport.updateState(JobSupport.kt:157)
at kotlinx.coroutines.experimental.JobSupport.makeCompletingInternal(JobSupport.kt:568)
at kotlinx.coroutines.experimental.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:552)
at kotlinx.coroutines.experimental.AbstractCoroutine.resumeWithException(AbstractCoroutine.kt:110)
at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:150)
at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:14)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.AssertionError: Test failed predictably
at org.junit.Assert.fail(Assert.java:88)
at kotlin.test.junit.JUnitAsserter.fail(JUnitSupport.kt:56)
at kotlin.test.AssertionsKt__AssertionsKt.fail(Assertions.kt:89)
at kotlin.test.AssertionsKt.fail(Unknown Source)
at completable.future.test.CompletableFutureTest$testFailAsCompletableFuture$executeJob$1.doResume(CompletableFutureTest.kt:14)
at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:42)
... 7 more
dharrigan
07/31/2018, 8:09 PMdharrigan
07/31/2018, 8:17 PMasad.awadia
07/31/2018, 10:48 PMuhe
08/02/2018, 8:40 AM@RestrictsSuspension
class Foo() {
suspend fun bar() = Unit
}
// ERROR: Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
fun yUnoWork() = runBlocking { Foo().bar() }
winteryoung
08/03/2018, 2:09 AMwinteryoung
08/03/2018, 2:14 AMjw
08/05/2018, 8:40 PMlouiscad
08/05/2018, 10:42 PMHandler?
.
Since coroutines already have the concept of dispatcher, there's a kind of concept duplication (although Handler
is single threaded, unlike `CoroutineDispatcher`s).
I'd like to avoid this leaking into the API of my library as method parameters, so I'm thinking about putting the Handler
into the CoroutineContext
so it can be retrieved by the library. Do you think it's a good usage of CoroutineContext
ThreadLocal-like abilities?mp
08/05/2018, 10:53 PMCompletionStage.asDeferred()
) into Deferred
for use in suspend
functions? If not, I can always adapt code from asDeferred
, but if there’s something supported out there, might as well use itske
08/06/2018, 4:17 PMamrelmasry
08/06/2018, 7:35 PMyield()
is doing?
@Test
fun testLaunchAndYieldJoin() = runTest {
expect(1)
val job = launch(coroutineContext) {
expect(3)
yield()
expect(4)
}
expect(2)
assertTrue(job.isActive && !job.isCompleted)
job.join()
assertTrue(!job.isActive && job.isCompleted)
finish(5)
}
Alowaniak
08/06/2018, 9:59 PMAlowaniak
08/06/2018, 9:59 PMdiesieben07
08/06/2018, 10:00 PMval a: Deferred<Boolean> = TODO()
val b: Deferred<Boolean> = TODO()
val result = async {
a.await() || b.await()
}
Alowaniak
08/06/2018, 10:07 PMdiesieben07
08/06/2018, 10:12 PMjw
08/06/2018, 10:40 PMselect
groostav
08/07/2018, 1:46 AMDeferreds
are eager by default, in other words, when you write async
, we dont create a lazy coroutine by default. In other words, by expressing right
as a Deferred, its already running, so you've already lost the point of short-circuiting typically. If you chose to express it as a suspend () -> Boolean
though...bdawg.io
08/07/2018, 5:41 PMval a: Boolean
val b: Boolean
a || b
, a
is evaluated first and THEN b
, which the results happen to be available already so it can immediately evaluate. It seems inconsistent that a Deferred
variant would potentially evaluate b
first instead of awaiting the value of a