https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
coroutines
  • a

    aeruhxi

    08/20/2018, 12:23 PM
    I am currently out of reach from computer.. I will let you know when I try
    👍 1
    l
    • 2
    • 8
  • o

    Olekss

    08/20/2018, 12:32 PM
    hmm do I understand correctly that coroutines is very good for gaming Like Each object in the game can be represented by coroutine running in infinite loop and each loop ends with "yield" and you can have like zillion of sprites moving on the same shared thread and be sure that kotlin itself will fairly deal with state changes (given I yield)
    e
    • 2
    • 1
  • l

    littlelightcz

    08/20/2018, 5:26 PM
    I'm not sure if I already mentioned it before, anyway, after a few weeks of coding TornadoFX apps I got used to create these 2 extension functions to ease up my code a bit:
    launchUI {}
    for
    launch(JavaFx) {}
    and
    commonPool {}
    for
    withContext(CommonPool) {}
    . If something similar would be considered to be added to the coroutines-javafx and base coroutines libraries, that would be a thumbs up from me 👍🙂
    👍🏼 1
    i
    t
    +2
    • 5
    • 15
  • b

    bdawg.io

    08/21/2018, 2:31 PM
    @Martin Devillers have you tried verifying the 2nd argument passed is a
    Continuation
    ?
    m
    g
    • 3
    • 14
  • j

    JoeHegarty

    08/21/2018, 9:26 PM
    Kind of an open ended question but how are folks handling backpressure in relation to coroutines? Say I have an existing pipeline in project reactor, messages are pumped in one side, queued, fed into a ParallelFlux and then transformed and ultimately consumed by the app. The queue and the "rails" in the pflux effectively give you back pressure so only X messages are in flight in the pipeline concurrently and as one message on a rail finishes it picks up the next from the queue. That seems like it'd be pretty hard to model as easily with coroutines. Am I missing something?
    e
    g
    • 3
    • 6
  • g

    groostav

    08/21/2018, 11:51 PM
    Is there a way I can specify to
    produce
    that I dont want it to run its block until somebody calls
    recieve
    from it? IE a kind of pull based channel?
    l
    u
    • 3
    • 5
  • g

    groostav

    08/22/2018, 9:08 PM
    oh, here's a wonderfully esoteric question: I encountered this while refactoring...
    Untitled.kt
    e
    • 2
    • 1
  • m

    muralimohan962

    08/23/2018, 4:46 AM
    Is CommonPool a default dispatcher?
    :yes: 1
    g
    e
    • 3
    • 3
  • a

    aaverin

    08/23/2018, 3:24 PM
    pseudocode:
    fun funToTest() = async {
       registerDevice()
       //... and lots of extra logic here
    }
    
    private suspend fun registerDevice() = suspendCoroutine {
     // handle complex callback logic and do it.resume(data) for suspendCoroutine
    }
    m
    • 2
    • 1
  • a

    aaverin

    08/23/2018, 3:31 PM
    How I test it now:
    @Test
        fun `ok result of registration results in success`() = blocking {
            val result = classToTest.execute(appConfig).await()
            mockRegisterResponseSuccess(ApiResponseStatus.OK)
            mockInitAppPurchasesSuccess()
            result.should.be.equal(trackingId)
        }
    m
    g
    • 3
    • 3
  • e

    elizarov

    08/23/2018, 4:44 PM
    📣 📣 📣
    kotlinx.coroutines
    version
    0.25.0
    is released. It has reworked/consistent/documented exception handling model, convenient thread-locals for coroutines, SLF4J MDC integration, and more. See https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.25.0
    👏 3
    👍 5
    🎉 19
    e
    v
    o
    • 4
    • 4
  • b

    bj0

    08/23/2018, 5:59 PM
    so we should be catching
    JobCancellationException
    instead of
    CancellationException
    ?
    e
    • 2
    • 12
  • k

    kevinherron

    08/24/2018, 2:32 AM
    I’ve written some
    debounce
    extensions for
    SendChannel
    and `ReceiveChannel`… any interest in a PR? anybody else find they’ve needed these?
    l
    • 2
    • 2
  • a

    aaverin

    08/24/2018, 5:41 AM
    I am a little confused. So if I will not wrap
    await()
    call in try/catch I might never ever know that there was an exception inside? Or will that exception then thrown as usual?
    fun main(args: Array<String>) = runBlocking {
        val job = launch {
            println("Throwing exception from launch")
            throw IndexOutOfBoundsException() // Will be printed to the console by Thread.defaultUncaughtExceptionHandler
        }
        job.join()
        println("Joined failed job")
        val deferred = async {
            println("Throwing exception from async")
            throw ArithmeticException() // Nothing is printed, relying on user to call await
        }
        try {
            deferred.await()
            println("Unreached")
        } catch (e: ArithmeticException) {
            println("Caught ArithmeticException")
        }
    }
    g
    • 2
    • 2
  • a

    aaverin

    08/24/2018, 5:43 AM
    async and produce ... are relying on the user to consume the final exception
    – what if user doesn’t consume final exception, will it be thrown out of async/produce or just quietely hidden?
    g
    • 2
    • 6
  • l

    louiscad

    08/24/2018, 9:38 AM
    Wild idea: allow
    suspend val
    and
    suspend operator fun getValue
    to allow
    by suspendLazy { ... /* a coroutine */ }
    delegation. I'm not sure It's a good idea though
    g
    • 2
    • 1
  • a

    aaverin

    08/24/2018, 12:32 PM
    So yes, I tried and code inside
    async
    only runs when I call
    await
    m
    l
    g
    • 4
    • 20
  • p

    Paul Woitaschek

    08/24/2018, 3:29 PM
    -.txt
    i
    l
    • 3
    • 2
  • l

    louiscad

    08/24/2018, 6:23 PM
    @withoutclass Always use
    consume
    or
    consumeEach
    . BTW, this is getting me wondering if
    for
    loop on a channel without
    consumption
    should raise a warning…
    ☝️ 1
    b
    • 2
    • 5
  • w

    withoutclass

    08/24/2018, 6:23 PM
    They don’t work for me when I’m reading in batches
    l
    k
    • 3
    • 15
  • p

    Paul Woitaschek

    08/26/2018, 11:08 AM
    Sometimes I wish to have a compiler flag for not inlining anything for debugging
    o
    l
    • 3
    • 7
  • a

    adev_one

    08/27/2018, 1:21 PM
    I’m trying to implement something like
    UI
    dispatcher from anko but on iOS My
    build.gradle
    buildscript {
        ext.kotlin_version = '1.2.51'
        ext {
            coroutines_version = "0.25.0"
        }
    }
    
    apply plugin: 'kotlin-platform-native'
    
    sourceSets {
        main {
            component {
                baseName.set("NF")
                outputKinds = [FRAMEWORK]
                target 'ios_arm64', 'ios_x64'//, 'ios_arm32'
            }
        }
    }
    
    dependencies {
        compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
        <...>
    }
    IosDisplayContext.swift
    import NF
    
    @objc
    class IosDisplayContext: NSObject, NFCoroutineDispatcher {
    
    }
    I’m getting error
    Use of undeclared type 'NFCoroutineDispatcher'
    . How can I implement public protocols of coroutines library by my Swift code?
    e
    • 2
    • 1
  • a

    aaverin

    08/27/2018, 3:48 PM
    Is it possible to wrap around callback with
    produce
    somehow, similar to
    suspendCancellableCoroutine
    ? I am trying to have coroutines for Firebase Firestore and they use
    addSnapshotCallback
    to observe hot data
    b
    • 2
    • 1
  • a

    aaverin

    08/27/2018, 3:48 PM
    At the moment I get an error that
    send
    can only be called in coroutine context, that is hidden by the callback function
    v
    b
    • 3
    • 13
  • k

    kevinherron

    08/28/2018, 3:23 AM
    @elizarov will the
    AbstractChannel
    APIs stabilize before release? I may have a use for a
    Channel
    backed by a priority queue but want to re-use as much as possible…
    e
    g
    • 3
    • 5
  • t

    tyjka

    08/28/2018, 3:33 AM
    Here in guide https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#cancellation-and-exceptions in the code example delay() is called in a child coroutine, and then the child coroutine is cancelled. If yield() is not called on the parent coroutine then child won’t be canceled. Why calling yield() on parent makes child cancellable, whereas delay() has to be cancellable by default?
    v
    • 2
    • 3
  • d

    Dmytro Danylyk

    08/28/2018, 8:37 AM
    This may be interesting to those who started working with coroutines: https://twitter.com/dmytrodanylyk/status/1034357859293622272 We have been discussing with @nemi today, maybe custom coroutine dispatcher would be a way to handle such use-case?
    g
    v
    +3
    • 6
    • 28
  • r

    richodemus

    08/29/2018, 8:25 AM
    Anyone have a list of all the functions that are added for coroutines? (like async, runBlocking etc) or know where I can find it I find that it's something I'm missing when trying to learn them, to kinda answer the question "is there a better way of doing this?"
    g
    • 2
    • 9
  • d

    dstarcev

    08/29/2018, 10:12 AM
    Hi, is there a function that waits for multiple tasks to finish and aggregates their exceptions if so?
    e
    d
    d
    • 4
    • 3
  • i

    igorvd

    08/29/2018, 12:58 PM
    Hi, I'm trying to build an APK that uses coroutines... I'm getting an
    Error while generating the main dex list
    Running with the stacktrace, I can see that this is the cause:
    Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: kotlinx.coroutines.experimental.AbstractContinuation
    	at com.android.tools.r8.utils.ProgramClassCollection.resolveClassConflictImpl(ProgramClassCollection.java:64)
    	at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:25)
    	at java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:1990)
    	at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:24)
    	at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:124)
    	at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:123)
    	at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:86)
    	at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:41)
    	at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:111)
    	at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:83)
    	... 56 more
    Searching for jars that contains the
    AbstractContinuation
    , I can see that is present in:
    org.jetbrains.kotlinx:kotlin-coroutines-core:0.25.0
    org.jetbrains.kotlinx:kotlin-coroutines-core-common:0.25.0
    But my only dependency in build.gradle is:
    org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0
    I've notice that going back to version 0.23.4 fixed the problem. Maybe it's a bug with the version
    0.25.0
    . I can't test using the
    0.24.0
    , because I need the
    runBlocking
    in some parts.
    d
    • 2
    • 4
Powered by Linen
Title
i

igorvd

08/29/2018, 12:58 PM
Hi, I'm trying to build an APK that uses coroutines... I'm getting an
Error while generating the main dex list
Running with the stacktrace, I can see that this is the cause:
Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: kotlinx.coroutines.experimental.AbstractContinuation
	at com.android.tools.r8.utils.ProgramClassCollection.resolveClassConflictImpl(ProgramClassCollection.java:64)
	at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:25)
	at java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:1990)
	at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:24)
	at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:124)
	at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:123)
	at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:86)
	at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:41)
	at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:111)
	at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:83)
	... 56 more
Searching for jars that contains the
AbstractContinuation
, I can see that is present in:
org.jetbrains.kotlinx:kotlin-coroutines-core:0.25.0
org.jetbrains.kotlinx:kotlin-coroutines-core-common:0.25.0
But my only dependency in build.gradle is:
org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0
I've notice that going back to version 0.23.4 fixed the problem. Maybe it's a bug with the version
0.25.0
. I can't test using the
0.24.0
, because I need the
runBlocking
in some parts.
d

dekans

08/29/2018, 1:32 PM
This is a building option not supported by Android build tools. https://github.com/Kotlin/kotlinx.coroutines/issues/510 No solution for now 😕 (exeption trying with AGP 3.3 which still is alpha)
👍🏼 1
i

igorvd

08/29/2018, 1:36 PM
😞 But I'm already using the AGP 3.3.0-alpha05, AS 3.3 canary and gradle 4.9.. Maybe I should stick with the 0.23.4 for a while...
d

dekans

08/29/2018, 1:46 PM
It seems that you need R8 to be enabled un your gradle.properties
From the comments of this issue. I stick to v0.24 until we have a fix 😞
i

igorvd

08/29/2018, 1:58 PM
I've checked with the r8 enabled 😕 Same problem
View count: 3