geekasm
09/28/2017, 9:10 AMbj0
09/29/2017, 11:49 PMelizarov
10/01/2017, 6:54 AMkotlinx-coroutines-jdk8
module to your deps and use process.onExit().await()
.dave08
10/02/2017, 8:05 AMdave08
10/03/2017, 1:22 PMproduce { }
function?matej
10/05/2017, 5:06 PMjw
10/06/2017, 1:15 PMsuspendCoroutine
? That means that block finished executing before the result is returned?sdeleuze
10/06/2017, 1:19 PMreactor-core
3.1 (included in Bismuth
) is the real GA since the one shipped with Spring Framework 5 for which we garantee API stability, so no need to support the old one.kenkyee
10/07/2017, 11:21 AMelizarov
10/07/2017, 8:44 PMkotlinx.coroutines
version 0.19.1
is released. It is a patch that fixes a serious race in ArrayBroadcastChannel
(it was there since introduction) and updates kotlinx.coroutines.reactor
to leverage Bismuth release train. Full list of changes in here: https://github.com/Kotlin/kotlinx.coroutines/releasesraulraja
10/07/2017, 10:46 PMOption.monad().binding {
val a = Option(1).bind()
val b = Option(a + 1).bind()
yields(b)
}
//Option(2)
binding
is a Continuation and bind
is implemented as a COROUTINE_SUSPENDED
function that unwinds flatMap
calls until the entire binding is completed as shown here https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/typeclasses/MonadContinuations.kt#L53-L61
For this to work we are resorting to a dirty hack which is making the private label
and completion
properties visible so we can mutate them accordingly. https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/typeclasses/ContinuationUtils.kt
Do you know if there is a better way of doing this? Thanks in advance for any pointers in the right direction 🙂elizarov
10/08/2017, 6:48 AMokkero
10/08/2017, 12:34 PMlangara
10/08/2017, 2:35 PMDmytro Danylyk
10/09/2017, 6:14 AMjkbbwr
10/10/2017, 12:37 PM>> put multiple containers into one JVM instance, which allows to deploy many small Java applications in large scale, across data centers,use coroutines (from Da Vinci Machine project) to reduce context switches, implement quick Java warmup to obviate the need for “warming-up” occurred in initialization phase of the eCommerce applications
elizarov
10/10/2017, 1:44 PMdetouched
10/13/2017, 5:09 AMselect
that waits for the first successful result (opposed to the existing one that waits for the first completed clause, no matter exceptionally or not).
First of all, am I reinventing the wheel? If not, here's what I ended up with – does it make sense? Any issues you can see here?
private suspend fun <R, D : Deferred<R>> selectFirstSuccessful(deferredList: List<D>,
failedDeferredList: List<D>): Triple<R?, List<D>, List<D>> =
if (deferredList.isEmpty()) {
Triple(null, deferredList, failedDeferredList)
} else {
try {
select<Triple<R?, List<D>, List<D>>> {
deferredList.forEach { deferred ->
deferred.onAwait { result -> Triple(result, deferredList - deferred, failedDeferredList) }
}
}
} catch (e: Exception) {
val completedExceptionally = deferredList.filter { it.isCompletedExceptionally }
val notCompletedExceptionally = deferredList - completedExceptionally
selectFirstSuccessful(notCompletedExceptionally, completedExceptionally + failedDeferredList)
}
}
Full code with usage example is here: https://gist.github.com/detouched/73f366cb730ece629b9141dea96d3a98detouched
10/13/2017, 12:56 PMonAwait
instead of catch
in the case result
is "empty"?
I'm actually interested in the failures in some cases, so I need to somehow pass them through anyway to inspect them later.elizarov
10/16/2017, 7:42 PMelizarov
10/18/2017, 1:06 PMuli
10/18/2017, 4:19 PMcounter.send(GetCounter(response))
println("Counter = ${response.await()}")
counter.close() // shutdown the actor
}
elizarov
10/19/2017, 11:00 AMasyncio
analogue is a work in progress still. We’ll have some separate guide for it when it is releaseddave08
10/19/2017, 3:07 PMfunctionaldude
10/19/2017, 5:54 PMHashMap
which is only accessed and modified in a single coroutine context:
val pushNotificationGeneratorThread = newSingleThreadContext(name = "Push Notification Generator Thread")
suspend fun clear() = run(pushNotificationDispatcherThread) {
lastNotificationDates.clear()
}
suspend fun put(key: String, value: Any) = run(pushNotificationDispatcherThread) {
lastNotificationDates.put(key, value)
}
However sometimes I still get a ConcurrentModificationException
. In my understanding this should be threadsafe.eygraber
10/20/2017, 6:41 PMRunnable
that makes the network call and writes the response.
Using Rx it would look something like:
quoteService
.getQuote()
.flatMap(response::write)
.subscribeOn(<http://Schedulers.io|Schedulers.io>())
.subscribeBy(
onSuccess = {},
onError = {}
)
I'm not great with coroutines, but I assume it would look something like:
async {
try {
val quote = quoteService.getQuote().await()
response.write(quote)
catch(_: Exception) {}
}
Is it just about the style of programming, or do coroutines offer something major over the other approaches? I see a few places that mention coroutines are non-blocking, but they don't seem to be, at least not in the same way that non-blocking io works.
Can anyone help clarify this?julienviet
10/23/2017, 8:32 AMelizarov
10/23/2017, 11:24 AMuli
10/23/2017, 6:47 PMdave08
10/23/2017, 8:24 PMdave08
10/23/2017, 8:24 PMvoddan
10/23/2017, 8:27 PMdave08
10/23/2017, 8:30 PMvoddan
10/23/2017, 8:33 PMdave08
10/23/2017, 8:36 PMvoddan
10/23/2017, 8:38 PMbuildSequence
is kinda a side use of Coroutines, but it is nice to have, especially since :kotlin: is trying to compete withy Pythondave08
10/23/2017, 8:42 PMgroostav
10/24/2017, 5:46 PMgenerateSequence
will often require a when
statement where buildSequence
doesn't. I've used this for test-data where I want lazy creation of elements (IE, I cant simply enumerate them eagerly), consider:
val resources = buildSequence {
yield(makeExpensiveResourceOne())
yield(makeExpensiveResourceTwo())
}
with generate sequence
//no good, its eager
val resources = listOf(makeResourceOne(), makeResourceTwo()).toSeq()
val resources = (1 .. 2).toSeq().map {
when(it) {
1 -> makeExpensiveResourceOne()
2 -> makeExpensiveResourceTwo()
}
}
dave08
10/24/2017, 5:55 PMval resources = listOf(::makeExpensiveResourceOne,::makeExpensiveResourceTwo).toSeq().map { it() }
groostav
10/24/2017, 10:26 PMasync void doAnimation(){
characterModel.displayedFrame = hitFrame[0]
characterModel.location -= 5
nextFrame() //suspending function
characterModel.displaedFrame = hitFrame[1]
characterModel.location -= 2
nextFrame()
}
dave08
10/25/2017, 2:22 AMbuildSequence
is better than regular Kotlin sequence generators, like with yield on conditions and yieldall that can produce many next values in one shot that can be iterated through one by one.
Whereas regular sequences can generate only the next value from an isolated computation or as an accumulation of a previous result apon iterating through each value
So for concurrency there are no advantages over sequences, but there are more options on how to actually generate them.