pardom
02/26/2019, 4:37 PMrunBlocking
isn’t in common so that can’t be used.ansman
02/27/2019, 1:59 PMcoroutineScope
doesn’t accept a CoroutineContext
to merge with the parent context?streetsofboston
02/27/2019, 5:07 PMkevinherron
02/27/2019, 7:09 PMobobo
02/27/2019, 7:16 PMlaunch
? Should I just instance a new scope for the call? Documentation says that any uncaught exceptions will cancel the parent job.dewildte
02/28/2019, 12:07 AMjava.lang.NoClassDefFoundError: kotlinx/coroutines/BuildersKt
at RandomPanelAction.actionPerformed(RandomPanelAction.kt:17)
at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:220)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:237)
at com.intellij.ide.actions.GotoActionAction.lambda$performAction$7(GotoActionAction.java:352)
at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:120)
at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransactionLater$4(TransactionGuardImpl.java:271)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:447)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:431)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:415)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:781)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:722)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.BuildersKt PluginClassLoader[IntelliGlo.intelliglo-plugin, 0.0.1] com.intellij.ide.plugins.cl.PluginClassLoader@6d3678f6
at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:63)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 28 more
sitepodmatt
02/28/2019, 3:36 AMsitepodmatt
02/28/2019, 7:46 AM@UseExperimental(InternalCoroutinesApi::class)
fun Job.getParent() : Job? {
return (AbstractCoroutine::class.java as Class<*>)?.
getDeclaredField("parentContext")?.
also { it.isAccessible = true }?.
let { it.get(this) as? CoroutineContext? }?.
let { it[Job] }
}
sitepodmatt
02/28/2019, 10:20 AMclass RequestContextTest : StringSpec({
"playing with human context" {
runBlocking {
supervisorScope {
try {
val repoSize = async<String> {
// do remote
val somenestedOp = async<String> {
delay(100)
throw DomainException("oh no", Exception("400"))
}
somenestedOp.await()
}
repoSize.await()
} catch (de: DomainException) {
println("we will swallow")
}
}
}
println("we exited okay")
}
})
class DomainException(msg: String, t: Throwable) : Exception(msg, t)
louiscad
02/28/2019, 11:15 AMcoroutineScope { ... }
, I have an async
block that needs to be cancelled if some error callback comes in, and that exception coming in is the cause of the cancellation, so CoroutineScope.cancel()
doesn't suit my needs.
2. Is using CompleteableDeferred<T>(coroutineContext[Job])
safe? My guess is that it will cancel the scope with the proper exception if its completeExceptionnaly(…)
function is called, and it will itself be cancelled if the scope is cancelled from another place. Am I right about this? If so, I'm wondering why there's no completableDeferred<T>()
extension function for CoroutineScope
that would do it without needing to pass coroutineContext[Job]
.Dias
02/28/2019, 12:41 PMMartin Devillers
02/28/2019, 2:19 PMUnit
to a channel, which would count the number of items received and update that information. The items are processed by simply mapping the list to async
calls which process the item then send
to the progress channel, then doing awaitAll
on this channel. See the code.
The issue I’m running into is that the progress isn’t being broadcast along as items are processed. Instead, all the items are processed, then all the progress updates are sent, which isn’t very useful. As I understand it, this is because the dispatcher’s queue is “fair”, therefore it handles all the async
calls before handling the receive
calls of the actor.
If you have ideas on a better way to do this, I would really appreciate it. One solution that I see is to use the “fan-out” technique described in the coroutine guide, but this seems weird to me since I have a list, not a channel, and also because I lose the benefit of leaving the responsibility of determining the parallelism of processing to the coroutine dispatcher.
Thanks 🙂rrva
02/28/2019, 4:20 PMRyota
03/01/2019, 2:17 AMrunBlocking
usages and I’d love to get some pointer.
My goal is to start a blocking process with AWS Lambda, which would kick off a bunch of heavy tasks concurrently, and then returns the aggregate of the tasks when they are all completed (or when any canceled).
Because the Lamdba interface itself is not a suspending function (i.e. RequestHandler<I, O>
interface needs function with signature of public O handleRequest(I input, Context context)
), I will need a coroutine builder inside handleRequest
method to await for the tasks. I have read in a few places how runBlocking
is only meant to be used for unit testing mainly, and should not be used in production. What I want to achieve seems to require runBlocking
for good reason, but I am unsure if I’m missing something obvious.
Given serverless function requiring a blocking call, is runBlocking
a legitimate approach in this scenario? Or is there something that I’m missing? Thanks in advance for your support!jw
03/01/2019, 2:38 AMserebit
03/01/2019, 3:10 AMcoroutineScope
or supervisorScope
to one of my suspend functions not only stops the build, but breaks the Kotlin compiler completely!Davide Giuseppe Farella
03/01/2019, 12:58 PMDavide Giuseppe Farella
03/01/2019, 1:08 PMoverride suspend fun observeCount() = coroutineScope {
queries.count().asChannel().mapToOne( coroutineContext ).map { it.toInt() }
}
louiscad
03/01/2019, 2:37 PMwithContext
and coroutineScope
at some point!marcoferrer
03/01/2019, 5:02 PMcoroutineContext[Job]?.invokeOnCompletion {
if(it is CancellationException){
call.cancel(it.message,it.cause ?: it)
}
}
otakusenpai
03/01/2019, 6:15 PMansman
03/01/2019, 10:14 PMcoroutineScope {
launch(start = LAZY) {}
}
asad.awadia
03/01/2019, 11:55 PMMatej Kormuth
03/02/2019, 3:14 PMwhile(true) { ... delay(3000) }
code in it. Is is possible to somehow trigger skip of the delay (waiting 3s) and run the while loop body immediately?asad.awadia
03/03/2019, 6:42 AMasad.awadia
03/03/2019, 7:25 AMbogdoll
03/03/2019, 6:27 PMaksh1618
03/03/2019, 7:09 PMawait()
on both, it runs. Is this a bug with the playground?groostav
03/03/2019, 7:39 PMUnconfined
to try and keep stacks neat. Namely I'd like to use an unconfined consumer to keep the producer on the stack trace, But I think there's a races making my life hard. AFAIK the contract with unconfined is so weak (and is aimed at performance, not debugability) that perhaps this isn't a bug per se, but Id still like to see it.
Proof-of-concept:
https://gist.github.com/Groostav/f8ef01ed830c14c394ac5b992d981aa1
if you put a breakpoint on send
and walk-through the the downstack implementation it will eventually invoke the receiver, If you just run the test, on my machine, the runBlocking
event loop will invoke the receiver.Alexjok
03/04/2019, 9:16 AMsuspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String) = async { }
Alexjok
03/04/2019, 9:16 AMsuspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String) = async { }
antonis
03/04/2019, 9:24 AMAlexjok
03/04/2019, 9:27 AMantonis
03/04/2019, 9:28 AMAlexjok
03/04/2019, 9:45 AMsuspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String): Deferred<Unit>
tseisel
03/04/2019, 4:16 PMJob
instead of Deferred<Unit>
, replacing async
with launch
.
You can then job.join()
to wait for the coroutine to complete its work.Alexjok
03/04/2019, 5:27 PM