kevinherron
12/14/2018, 4:02 AMGlobalScope.async
if the job `await()`ing it was cancelled.
https://gist.github.com/kevinherron/37155732ccd4c0587a69a9d86e16b448xenoterracide
12/14/2018, 5:35 AMgildor
12/14/2018, 6:05 AMkevinherron
12/14/2018, 12:28 PMfun main(args: Array<String>) {
val job = SupervisorJob()
val scope = CoroutineScope(job + Dispatchers.Default)
val deferred = GlobalScope.async(Dispatchers.Default, start = CoroutineStart.LAZY) {
delay(5000)
throw Exception("boom")
}
scope.launch {
try {
deferred.await()
} catch (e: Exception) {
println("error awaiting: $e")
}
}
runBlocking { job.cancelAndJoin() }
Thread.sleep(10000)
}
Dico
12/14/2018, 3:35 PMTristan Caron
12/14/2018, 4:54 PMkotlinx.coroutines
. What is the base? I suppose Deferred
is internally using Promise
, but what about Job
? Is it working with Worker
?Michal Fudala
12/16/2018, 11:39 AMisActive
, but here I would want to provide some kind of onCancelled
callback.
(here when I do cancel process is still present when doing ps aux
)dave08
12/16/2018, 3:09 PMproduce
on the receiving end (apart from a sealed class, all I need is a Long progress value, and it's a pity to have to box/unbox them unecessarily)?Dias
12/17/2018, 10:31 AMIt is a mix between a set and a map. Its elements have keys like in a map, but its keys are directly associated with elements, more like in a set.
But sets don't have keys, do they? And maps have their keys directly associated with values? Am I reading it wrong?dave08
12/17/2018, 1:41 PMnil2l
12/17/2018, 3:37 PMMartin Devillers
12/18/2018, 10:11 AMMartin Devillers
12/18/2018, 3:13 PMwithContext
and CompletableDeferred
.Alexander Romanov
12/18/2018, 4:11 PMval queueListener = launch {
while (isActive) {
// do something
}
}
Runtime.getRuntime().addShutdownHook(Thread {
<http://logger.info|logger.info> { "Cancellation requested" }
queueListener.cancel()
})
queueListener.join()
<http://logger.info|logger.info> { "Exiting program" }
why would “Exiting program” never show up?
are there any other way to do it? I am also considering channel that sends some cancellation event. But what wold be the better way to handle this?dave08
12/18/2018, 5:40 PMactor
send channels automatically closed at the end of the coroutineScope { }
that they're declared in?zak.taccardi
12/18/2018, 5:41 PMVsevolod Tolstopyatov [JB]
12/18/2018, 8:23 PMkotlinx.coroutines
1.1.0-alpha!
This is a major release with two new modules, a lot of improvements in testability and debuggability, various performance improvements and bug fixes.
Changelog:
* kotlinx-coroutines-test
module with testable Dispatchers.Main
* kotlinx-coroutines-debug
module with debug agent to track and debug active coroutines
* Stacktrace recovery mechanism that provides additional coroutine-based stacktraces in exceptions (enabled in debug mode)
* MainScope
and CoroutineScope.cancel
methods for simpler integration with structured concurrency
* CancellableContinuation
race between resumeWithException
and cancel
is now not treated as an uncaught exception
* Dispatchers.Default
CPU consumption in idle state is reduced
* JavaFx
dispatcher initialization bug fixed
Full changelog: https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.1.0-alphapawelbochenski
12/19/2018, 7:18 AMsashjakk
12/19/2018, 1:59 PMcancelAndJoin
completion block is not guaranteed to be executed right after cancelAndJoin
have completed? Tried to add some logging to see jobs actually finishedzak.taccardi
12/19/2018, 5:33 PMlazy
?Sam
12/19/2018, 9:51 PMzak.taccardi
12/19/2018, 9:52 PMzak.taccardi
12/19/2018, 9:56 PMjoao.alves
12/19/2018, 10:12 PMlaunch {}
am I not running the code inside on the main thread?joao.alves
12/19/2018, 10:17 PMjoao.alves
12/19/2018, 10:21 PMwithContext
and leave the launch
as it is, and with the base context defined as Main + job it works just finebdawg.io
12/20/2018, 2:25 AMspierce7
12/20/2018, 5:19 AMTolriq
12/20/2018, 9:01 AMdave08
12/20/2018, 1:15 PMdave08
12/20/2018, 1:15 PMgildor
12/20/2018, 1:50 PMdave08
12/20/2018, 2:13 PMsuspendCoroutine { }
so that it can run on it... 😕gildor
12/20/2018, 3:53 PMdave08
12/20/2018, 6:00 PMgildor
12/20/2018, 11:26 PM