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
  • f

    Francisco Javier Ruiz Rodriguez

    03/03/2020, 12:01 PM
    You cannot create class that inherits from a function
    m
    m
    +4
    • 7
    • 7
  • j

    Jan

    03/03/2020, 2:30 PM
    kind of android related, but which coroutine scope would you use in background services? e.g. intent services or job services?
    e
    s
    +3
    • 6
    • 10
  • s

    snowe

    03/03/2020, 4:57 PM
    I haven't touched coroutines in a while.
    runBlocking
    is now showing a
    deprecated
    warning, but I can find no information about this anywhere on the internet, not even the actual documentation https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html. Anyone know what is up with
    runBlocking
    ? What will it be in 1.4?
    o
    l
    • 3
    • 23
  • d

    David Glasser

    03/03/2020, 7:23 PM
    I'm looking for a coroutine equivalent of CountdownLatch (even just for the most basic n=1 case) where one coroutine can block until another coroutine says it can go. What am I looking for?
    o
    d
    e
    • 4
    • 10
  • a

    asad.awadia

    03/04/2020, 1:12 AM
    There seems to be a lot of experimental/obsolete annotations on things - any ideas when those will go away? Specifically around things like tickers/produce/consume etc
    l
    e
    • 3
    • 2
  • b

    Brendan Weinstein

    03/04/2020, 4:50 AM
    Trying to run macx64Test of
    native-mt
    branch of the coroutines library using kotlin 1.3.70 and getting the below error message:
    Expiring Daemon because JVM heap space is exhausted
    Any pointers? When I've been running into ios-specific issues in my codebase, I've been using the nativeTest setup in coroutines to write sanity tests to confirm or reject learnings. It takes a good 1-2 minutes with kotlin 1.3.61 to compile and run the tests though, so I am eager to see some improvement.
    i
    l
    e
    • 4
    • 8
  • a

    aeruhxi

    03/04/2020, 9:15 AM
    /**
     * You can edit, run, and share this code. 
     * <http://play.kotlinlang.org|play.kotlinlang.org> 
     */
    
    import kotlinx.coroutines.*
    
    fun main() {
        println("Hello, world!!!")
        CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
            (1..1000).forEach {
                suspend {
                    delay(2000)
                    print("Testing...")
                }
            }
        }
    }
    What kind of block is
    suspend {}
    ?
    e
    • 2
    • 2
  • m

    Mohamed Ibrahim

    03/04/2020, 3:03 PM
    In Flow, Why there's a
    completion
    listener with throwable , wouldn't be just simpler to provide it for just completion, and we already have
    catch {}
    z
    e
    • 3
    • 2
  • t

    Timur Atakishiev

    03/04/2020, 3:13 PM
    Hi all. Imagine I have a server that is adding an objects to queue continuously and I have a n-amount of threads that taking an object from queue, does some computation and saving result to database. Is it possible to do the task in the same way with coroutines, and if it is can someone help me please?
    z
    • 2
    • 1
  • y

    Yashdeep Patel

    03/04/2020, 4:10 PM
    Is there a way to add suspended functions in processing Queue (or similar). I have use case where I am getting different callbacks that updates same entity in database. Instead of execute suspended functions async, I want to execute them in same order that callback was received. Is there a way to do it?
    z
    t
    • 3
    • 2
  • z

    zak.taccardi

    03/04/2020, 8:34 PM
    is a channel always first in first out? Can I receive from a channel based on a filter, and if that filter fails to pass, leave those items in that channel? I have
    Channel<T>
    , and that
    T
    has two subclasses,
    T.One
    and
    T.Two
    . I need the first emission of
    T.Two
    to initialize some state in a coroutine, and after that I want to observe all emissions of
    T
    . But if
    T.One
    emits first, I want to queue it up (leave it in the channel), and allow it to emit once the first instance of
    T.Two
    finishes emitting.
    z
    r
    • 3
    • 7
  • e

    elect

    03/04/2020, 10:53 PM
    porting some c++ code to kotlin, I'm dealing with this right now. Since I'm a newbie in coroutines, I'd like to ask you if I'm better implementing this via a
    Thread
    or a kotlin coroutine..
    Untitled
    g
    • 2
    • 1
  • a

    agta1991

    03/05/2020, 11:41 AM
    Hi, has anyone came across InvalidMutabilityExceptions when using Flow combine operators on native targets? I'm using the 1.3.3-native-mt version.
    e
    • 2
    • 5
  • j

    Javier

    03/05/2020, 10:16 PM
    I think I got a lint issue when I use a suspend function as parameter
    s
    o
    e
    • 4
    • 17
  • m

    mingkangpan

    03/06/2020, 9:01 AM
    calling launch within launch is not structured concurrency anymore right?
    val upperJob = launch {
     val jobFoo1 = launch {
          foo1()
       }
       val jobFoo2 = launch {
          foo2()  
       } 
    }
    upperJob.cancel() //won't cancel jobFoo1 and jobFoo2
    right? I have to use
    async
    here
    k
    s
    • 3
    • 38
  • m

    mingkangpan

    03/06/2020, 10:25 AM
    supervisorScope {
        async {
            throw Exception()
        }
    
        async {
            throw Exception()    
        }
    }
    ^ app doesn't crash
    supervisorScope {
        launch {
            throw Exception()
        }
    
        launch {
            throw Exception()    
        }
    }
    ^ app crashes what am I doing wrong?
    m
    e
    • 3
    • 18
  • p

    Paul Woitaschek

    03/06/2020, 11:47 AM
    @elizarov https://bintray.com/kotlin/kotlinx/kotlinx.coroutines/1.3.4 Somethings wrong
    🚧 1
    e
    v
    • 3
    • 5
  • v

    Vsevolod Tolstopyatov [JB]

    03/06/2020, 12:31 PM
    📣 📣 📣 kotlinx.coroutines 1.3.4 is here! • Size of the resulting DEX of kotlinx.coroutines basic usages is significantly reduced • A human-readable actionable error is thrown when
    awaitClose
    is missing from
    callbackFlow
    •
    Flow
    exception transparency is now deterministically ensured •
    ReceiveChannel.asFlow
    extension added • Kotlin 1.3.70: opt-in annotations,
    coroutineContext[CoroutineDispatcher]
    API support • Performance improvements in
    Job
    ,
    Channel
    and
    Dispatchers.Default
    Full changelog: https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.3.4
    🎉 20
    💪 5
    r
    e
    • 3
    • 3
  • r

    Robert

    03/06/2020, 12:49 PM
    https://kotlinlang.slack.com/archives/C0B8ZTWE4/p1583498932054400
    e
    • 2
    • 1
  • s

    Slackbot

    03/06/2020, 9:36 PM
    This message was deleted.
    s
    e
    • 3
    • 2
  • l

    Luis Munoz

    03/06/2020, 10:02 PM
    For a channel what is the opposite of a flatMap, in other words how to take a channel of some array and start sending the values individually?
    b
    d
    • 3
    • 6
  • c

    Czar

    03/07/2020, 9:40 AM
    Hi. I'm just starting to use coroutines. I need to create a refreshable countdown thingie. Basically it has to do something 10 minutes after some event, if the event happens during those 10 minutes again, countdown should be refreshed. Here's my naive implementation, any suggestions? Am I shooting myself in the foot here? Should I add synchronization/locking?
    RefreshableCountDown_kt.kt
    l
    • 2
    • 47
  • s

    sasikanth

    03/08/2020, 1:14 PM
    Hello everyone. Is there a alternative to
    ObservableTransformer
    when using
    Flow
    or
    Channel
    ?
    p
    s
    • 3
    • 8
  • j

    jbnizet

    03/08/2020, 10:02 PM
    Hi. I’m starting to learn about coroutines and flows, and I’m wondering how one might do the equivalent of reactor’s
    Flux.flatMapSequential()
    , i.e. a flattenMerge(), but which would emit the values in the initial order of the merged flows. Any idea? I find such an operator quite useful, for example when you want to send HTTP requests in parallel, but with a limited concurrency, and still want to process the responses as if they had been sent sequentially.
    o
    b
    • 3
    • 8
  • c

    Czar

    03/09/2020, 3:16 PM
    I need to return last element of the flow along with its index, is there a prettier way?
    flow.kts
    s
    • 2
    • 2
  • j

    Joan Colmenero

    03/09/2020, 5:12 PM
    Hey all can you guys explain me a little bit about EmptyCoroutineContext and ContinuationInterceptor I do not get it at all. I'm learning about coroutine contexts and I found these
    z
    z
    • 3
    • 11
  • d

    David Glasser

    03/09/2020, 5:42 PM
    If I have a
    Channel<Unit>(capacity = Channel.UNLIMITED)
    and I never close it, is it guaranteed that
    offer
    will always succeed?
    z
    • 2
    • 21
  • z

    zak.taccardi

    03/09/2020, 5:57 PM
    Can someone explain why
    Result
    was added to the standard lib, when it’s effectively useless outside of Coroutines? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-result/ A standard
    Result<T>
    type that we could use as a return value would be incredible useful, and this seems to be a waste of a namespace?
    z
    • 2
    • 12
  • n

    napperley

    03/10/2020, 1:52 AM
    What is the current status of the Actor API in the KotlinX Coroutines library? I have a program (Industrial software that behaves like a Linux Daemon) running in production that heavily relies on the API, and would very likely break if a newer version of the KotlinX Coroutines library is used.
    z
    r
    s
    • 4
    • 5
  • n

    napperley

    03/10/2020, 6:02 AM
    What major concurrency models will be supported long term by the KotlinX Coroutines library?
    e
    • 2
    • 3
Powered by Linen
Title
n

napperley

03/10/2020, 6:02 AM
What major concurrency models will be supported long term by the KotlinX Coroutines library?
e

elizarov

03/10/2020, 8:15 AM
Can you be more specific, please, on what “concurrency models” you are interested in?
n

napperley

03/10/2020, 9:00 PM
Actor, which you might have seen mentioned in a post I made in #coroutines ( https://kotlinlang.slack.com/archives/C1CFAFJSK/p1583805157272700 ). Other concurrency models I am interested in are CSP, and Worker. Will the Worker model ( https://github.com/JetBrains/kotlin-native/blob/master/CONCURRENCY.md ) be confined to Kotlin Native, or will it be accessible on other Kotlin platforms (Kotlin JVM, Kotlin JS) through a separate library?
e

elizarov

03/11/2020, 12:23 PM
All are supported and will be supported. They are nothing more than coroutines connected by channels in certain model-specific ways.
View count: 10