bjartek
01/10/2018, 8:21 PMbdawg.io
01/11/2018, 8:05 PMjmfayard
01/13/2018, 9:35 AMelizarov
01/13/2018, 9:36 AMkotlinx.coroutines
version 0.21.1
is released with bug fixes and performance improvements for both JVM and JS. See here for details: https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.21.1eddy_wm
01/14/2018, 10:15 AMmcastiblanco
01/15/2018, 2:33 AMfun main(args: Array<String>) = runBlocking{
val dispatcher = newFixedThreadPoolContext(10, "myPool")
val jobs = ArrayList<Job>()
for (i in 1..10) {
jobs.add(launch(dispatcher) {
println("Running in ${Thread.currentThread().name}")
Thread.sleep(2000)
})
}
for (job in jobs) {
job.join()
}
}
which then prints something like
Running in myPool-1
Running in myPool-2
Running in myPool-3
Running in myPool-4
Running in myPool-5
Running in myPool-6
Running in myPool-7
Running in myPool-8
Running in myPool-9
Running in myPool-10
mcastiblanco
01/15/2018, 2:36 AMgildor
01/15/2018, 2:37 AMkenkyee
01/15/2018, 4:18 PMr4zzz4k
01/15/2018, 8:10 PMfun processor(input: ReceiveChannel<A>): ReceiveChannel<B> = produce {
input.consumeEach {
...
send(...)
}
}
And if not, is there more idiomatic way to do this chaining?r4zzz4k
01/16/2018, 4:09 PMConflatedChannel
without removing it?r4zzz4k
01/16/2018, 7:31 PMCompletableDeferred
, thank you very much for this suggestion!
Here's the final sample: https://try.kotlinlang.org/#/UserProjects/dsu5vhgcr0ls2h0flirmp3pf9g/ga94a9qaeq9e6v6s5bncbb75k3lovis
01/17/2018, 8:31 AMenable
coroutines? (e.g. kotlin.experimental.coroutines = 'enable'
in build.gradle)
I can’t seem to find it in the documentation and appearently it’s working without it. (but then again I’m not using the whole feature set)elizarov
01/19/2018, 4:06 PMr4zzz4k
01/19/2018, 7:27 PMsuspend
?
I.e. there is no way to avoid explicit type here:
val lambda: suspend (String) -> Unit = { input: String -> /* body */ }
elizarov
01/20/2018, 10:41 AMCoroutineDispatcher
. For example, if you are running your coroutines under Android UI
dispatcher, then it users Android-specific API to schedule execution after a specified time interval passes.dh44t
01/21/2018, 1:40 PMjw
01/22/2018, 9:51 PMsuspend fun sum(): Long
inside which I have a reference to something with the method suspend fun consume(consumer: suspend (Long) -> Unit)
. The implementation is the obvious thing:
var sum = 0L
numbers.consume { sum += it }
return sum
Now let's say I want to specify a maximum number of numbers. How can I cause the numbers.consume
to stop pushing numbers at me once that max is hit?bj0
01/22/2018, 11:51 PMactor
elizarov
01/23/2018, 4:20 PMgildor
01/24/2018, 8:32 AMchristophsturm
01/24/2018, 1:15 PMelizarov
01/24/2018, 9:38 PMkotlinx.coroutines
version 0.22
released. AbstractCoroutine
class now has public and stable API for extensions/integration. https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.22mcastiblanco
01/25/2018, 5:29 AM0.22
and Kotlin 1.2.21
. I put the comment on the ticket 👍enleur
01/26/2018, 12:00 AMlouiscad
01/26/2018, 4:35 PMfun SomeReceiver.someFunction(parentJob: Job) {
someNonSuspendingCode()
setOnErrorListener { errorCode ->
parentJob.cancel(SomeException(errorCode))
}
}
I'm wondering if I should make it a suspend fun
so I can get the current job from the coroutineContext (currently available in the intrisics package) and remove this not so nice (IMHO) parentJob
parameter.
If I did, it'd look like this:
2️⃣
suspend fun SomeReceiver.someFunction() {
val currentJob = coroutineContext[Job]!!
someNonSuspendingCode()
setOnErrorListener { errorCode ->
currentJob.cancel(SomeException(errorCode))
}
}
r4zzz4k
01/26/2018, 5:02 PMclass LoggingLinkedListChannel<E>(private val tag: String): LinkedListChannel<E>() {
override fun offerInternal(element: E): Any {
println("[$tag] $element")
return super.offerInternal(element)
}
}
val chan = LoggingLinkedListChannel<Int>("tag") // was Channel<Int>(Channel.UNLIMITED)
Is it even valid way to do this? It seems to be working for my simple use-case, but still.
As another way to do that was trying to get this working with .map { println(it); it }
, but it throws away capacity as it's effectively creates another channel.enleur
01/26/2018, 5:11 PMfun <E> ReceiveChannel<E>.onEach(context: CoroutineContext = Unconfined, action: (E) -> Unit): ReceiveChannel<E> =
produce(context) {
consumeEach {
action(it)
send(it)
}
}
Olekss
01/27/2018, 4:41 PMlouiscad
01/27/2018, 9:18 PMlouiscad
01/27/2018, 9:18 PMvoddan
01/27/2018, 9:29 PMlouiscad
01/29/2018, 8:19 AMr4zzz4k
01/29/2018, 1:30 PM