https://kotlinlang.org logo
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
  • w

    withoutclass

    09/06/2018, 3:07 PM
    Is there any reason to use
    coroutineContext
    with
    withContext
    ?
    e
    • 2
    • 2
  • v

    v0ldem0rt

    09/06/2018, 6:12 PM
    atomicfu seems like good fit but what difference it has with Java's
    Atmoic*
    j
    e
    +2
    • 5
    • 11
  • m

    matt tighe

    09/06/2018, 6:13 PM
    what’s the recommended way of doing something like this:
    fun refreshData() {
            networkStatus = Status.ACTIVE // class member
            launch(CommonPool) {
                asyncAwait {
                    remoteSource.fetchData().forEach {
                        roomDatabase.dao().insertData(it)
                    }
                    networkStatus = Status.INACTIVE
                }
            }
        }
    i’d like to be able to unit test that the status is updated while the coroutine is running
    j
    d
    g
    • 4
    • 13
  • i

    iLobanov

    09/07/2018, 4:40 AM
    Hi all. Need some help. What is the best way to return result of Listener callback function as result of my function which create it? Should I use channel to achive this or something like that?
    fun someFunction() : SomeResult {
        val someObj =  SomeObj(SomeListenr { result ->
                  SomeResult(result) // <- WANT THIS
            }
        )
        someObj.start()
    }
    g
    u
    • 3
    • 41
  • p

    Paul Woitaschek

    09/07/2018, 3:17 PM
    Now I want to combine these two so I can expose another channel of
    data class Person(val userName : String, age : Int)
    v
    l
    • 3
    • 9
  • p

    Paul Woitaschek

    09/07/2018, 3:55 PM
    However that
    increasePortionCount
    does not emit
    v
    • 2
    • 2
  • b

    bj0

    09/08/2018, 7:20 AM
    I
    launch(coroutineContext +IO) { channel.consumeEach { ... } }
    . I feed the channel from another coroutine that runs every 15s, and in the
    consumeEach
    i do a network send (through a cpp library). This works fine for a couple minutes but eventually this coroutine stops executing and the cpu usage of the process goes from .02% to 70%. This is on a desktop. If I remove the
    IO
    and use the
    CommonPool
    it works fine. There are no errors or exceptions, the coroutine just stops and the cpu goes nuts. Is there anything I can do to try and figure out whats happening?
    e
    e
    • 3
    • 2
  • n

    napperley

    09/09/2018, 6:47 AM
    This test doesn't seem to execute. Nothing is outputted to the console except a Jest async timeout error message.
    Kotlin_JS_UI_Test.kt
    t
    e
    • 3
    • 5
  • f

    freddiewang

    09/11/2018, 3:48 AM
    does anyone know how
    suspendCoroutineUninterceptedOrReturn
    or
    intercepted
    is generated in coroutine library? I’m confused about why some core functions are auto-gen… Any specific reason?
    e
    • 2
    • 4
  • f

    freddiewang

    09/11/2018, 4:38 AM
    @Dico thanks for your answer! Actually i don’t understand Kotlin’s intrinsic very well, are the intrinsic functions platform-dependent?
    i
    • 2
    • 1
  • d

    dstarcev

    09/11/2018, 10:18 AM
    is there a function to iterate over Flux in a coroutine context? Something like this:
    someFlux.forEach {
       val result = callAnotherSuspendingFunction(it)
       doSomethingElse(result)
    }
    g
    • 2
    • 2
  • j

    Joe

    09/11/2018, 3:33 PM
    I have a unit test that calls a method with a
    launch(UI)
    in it, but I'm getting the following message
    java.lang.NoClassDefFoundError: Could not initialize class kotlinx.coroutines.experimental.android.HandlerContextKt
    j
    • 2
    • 2
  • a

    alexcouch

    09/12/2018, 4:54 AM
    So I'm curious about something: I'm trying to create a way so that different threads take input but only one thread is active at a time and I can switch between the threads and whatever input is taken goes to that thread. I'm not quite sure how to do it. I kinda did it using the JDK Thread api but it's not quite working out as well as I was hoping cause I need to keep input coming in until the active thread is changed and then the input is sent into the new active thread. I tried to look into coroutines but that only confused me even more. Any ideas?
    d
    • 2
    • 5
  • d

    Daniel Tam

    09/12/2018, 12:45 PM
    the second last link on this page 404s, but I'm not sure what it's meant to point to: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/is-active.html
    n
    • 2
    • 2
  • l

    louiscad

    09/12/2018, 2:01 PM
    Hey :android: developers, here are 2
    coroutineScope
    extensions for
    Lifecycle
    and
    LifecycleOwner
    (that you can use in AppCompatActivities, Fragments, LifecycleServices...) for changes in kotlinx.coroutines 0.26.0: https://gist.github.com/LouisCAD/58d3017eedb60ce00721cb32a461980f#file-lifecyclejob-kt-L30
    👍 2
    🎉 3
    e
    t
    • 3
    • 18
  • j

    Jonathan

    09/12/2018, 2:06 PM
    Can someone help me understand why I cannot replace
    awaitAll(one, two)
    by
    one.await(); two.await()
    in this code?
    -.kt
    m
    v
    c
    • 4
    • 15
  • d

    dekans

    09/12/2018, 2:24 PM
    I'm trying the new kotlinx 0.26.0 toys, I struggel on something. I had a
    Job
    that I used as a parent for coroutines in this class. At some point I did a
    job.join()
    to make sure all operations were over. Now, I made this class implement
    CoroutineScope
    , I run some operations in
    launch(Dispatchers.Main+job)
    But
    job.join()
    is not effective anymore, and I cannot use
    coroutineContext[Job]
    for it. How should I do to have a 'global'
    Job
    which I could use?
    e
    • 2
    • 5
  • j

    Jonathan

    09/12/2018, 2:55 PM
    Why is the
    JavaFx
    dispatcher not an extension property on
    Dispatchers
    ?
    e
    • 2
    • 3
  • s

    StevieB

    09/12/2018, 3:44 PM
    Is there a 0.26.0-eap13 version of kotlinx-coroutines somewhere? I cant seem to find it and I was having immense fun previewing all the new goodies, why stop now!
    v
    • 2
    • 3
  • j

    jw

    09/12/2018, 8:06 PM
    i feel extremely spoiled by the source links on the stdlib documentation and would love them on the coroutine docs 😁
    👍 4
    e
    • 2
    • 2
  • d

    Dias

    09/12/2018, 8:15 PM
    https://kotlinlang.slack.com/archives/C0922A726/p1536783109000100
    t
    g
    • 3
    • 3
  • d

    Dias

    09/12/2018, 8:16 PM
    I used python before, and I converted one of the http servers that I had into async/await app, I used async libraries like aiopg or aiohttp. But say I have jdbi/jdbc based app, how do I convert it into async using coroutines without an async library or spawning any additional threads?
    t
    • 2
    • 7
  • g

    gotoOla

    09/13/2018, 7:50 AM
    Hi! I have a question about coroutines. Right now I’m looking into building a load/pressure-test tool and I am using the ktor http client to execute like 1000 concurrent request towards another service. So far this seems to work out pretty well but I wanted to get some input from here if there are any gotchas I should watch out for Right now I am just using the commonpool (at least in my code and if I understood it correctly ktor-client will do the same) and it feels like there should be some performance hit somewhere were I spawn like 1000 tcp-connections on only cores-1 threads?
    s
    w
    • 3
    • 2
  • p

    poohbar

    09/13/2018, 12:42 PM
    @elizarov I must say this article of yours https://medium.com/@elizarov/structured-concurrency-722d765aa952 scared me a lot about the way Kotlin is developed. All these months coroutines were out we were being convinced that the "experimental" flag is just an unfortunate naming. That they are pretty much close to being stable and fully thought out yet the article hints that you truly had no idea what you were getting into. I think the changes proposed in the article are last-minute and quite drastic. How are we supposed to be comfortable about adopting coroutines now? What if you made a huge mistake somewhere again?
    Unfortunately, this example is wrong on many levels in very subtle ways.
    Seriously? So all these talks were full of completely wrong examples? And you just found out? It's not like these concepts are completely new to computer science, why not take more inspiration from other languages such as
    clojure.async
    ?
    e
    k
    +10
    • 13
    • 57
  • б

    Бежан Александр

    09/13/2018, 3:44 PM
    Hey guys. I’m getting error:
    ava.lang.VerifyError: Bad type on operand stack
    Exception Details:
      Location:
        app/Main$main$1$1.doResume(Ljava/lang/Object;Ljava/lang/Throwable;)Ljava/lang/Object; @1347: invokespecial
      Reason:
        Type 'java/util/Collection' (current frame, stack[2]) is not assignable to 'app/Main$main$1$1$doResume$$inlined$run$lambda$1'
    :stackoverflow: 1
    w
    i
    • 3
    • 5
  • r

    rocketraman

    09/13/2018, 5:31 PM
    I had a class that created a
    newSingleThreadContext
    and was passing that to
    launch
    . Is the right way to do this to now create a
    CoroutineScope
    that encapsulates that dispatcher, and then call
    launch
    with that scope?
    e
    i
    • 3
    • 16
  • e

    enleur

    09/14/2018, 5:17 AM
    replaced my cached thread pool dispatcher with
    <http://Dispatchers.IO|Dispatchers.IO>
    , now it cuts unused threads instant, but consumes more cpu
    e
    w
    v
    • 4
    • 7
  • a

    aaverin

    09/14/2018, 2:51 PM
    Having this method:
    fun setup() {
            if (!requiresMigration()) {
                launch { regularPaymentSetup.setup() }
            } else {
                launch { migrationPaymentSetup.setup(it) }
            }
        }
    How to unit-test that regularPayment is executed?
    launch
    starts a new coroutine and test fails
    j
    • 2
    • 11
  • b

    bj0

    09/14/2018, 4:53 PM
    without explicitly writing an actor for every handler
    w
    • 2
    • 4
  • m

    marcinmoskala

    09/14/2018, 6:46 PM
    Is there any UI for iOS that can be used?
    v
    • 2
    • 2
Powered by Linen
Title
m

marcinmoskala

09/14/2018, 6:46 PM
Is there any UI for iOS that can be used?
v

voddan

09/14/2018, 7:36 PM
Only what Apple provides
m

marcinmoskala

09/14/2018, 7:45 PM
class UI: KTKotlinx_coroutines_core_nativeCoroutineDispatcher {
        override func dispatch(context: KTStdlibCoroutineContext, block: KTKotlinx_coroutines_core_nativeRunnable) {
            DispatchQueue.main.async {
                block.run()
            }
        }
    }
View count: 4