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

    bdawg.io

    10/30/2018, 12:14 AM
    If you're going to immediately
    await
    on an
    async
    job, you might as well just use
    withContext
    a
    g
    • 3
    • 4
  • r

    Rohit Surwase

    10/30/2018, 4:12 AM
    How can we use `Coroutines with Dispatchers.IO`inside Android Service instead of
    HandlerThread + Looper
    ? I tried and it worked for limited use case but not sure about generic use case. I feel it is not a good practice and will not work for all cases? Is it?
    g
    • 2
    • 43
  • p

    Paul Woitaschek

    10/30/2018, 7:06 AM
    Are there any drafts \ keeps for cold channels?
    d
    • 2
    • 1
  • p

    Paul Woitaschek

    10/30/2018, 7:07 AM
    I'm still using rx as I need it to be cold most of the times and I find channels too complicated. Are there other stream abstractions built upon coroutines?
    j
    d
    • 3
    • 6
  • u

    uhe

    10/30/2018, 12:34 PM
    So I upgraded to 1.0.0 and I'm getting experimental warnings for all sorts of coroutine APIs (
    produce
    ,
    UNDISPATCHED
    , etc). According to the docs I can opt in via "the compiler argument -Xuse-experimental=kotlin.Experimental" but I can't for the life of me figure out how to specify this in my gradle files. I tried adding this to my root build.gradle, but it's not working:
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
            kotlinOptions {
                freeCompilerArgs += [
                        '-Xuse-experimental=kotlin.Experimental'
                ]
            }
        }
    Does anybody know how I can opt-in properly?
    👍 1
    g
    d
    • 3
    • 20
  • a

    Albert

    10/30/2018, 2:01 PM
    How do I initiate
    actor
    properly? I tried:
    GlobalScope.actor { }
    But it is annotated with
    ObsoleteCoroutinesApi
    g
    g
    • 3
    • 8
  • j

    Jonathan

    10/30/2018, 4:20 PM
    Since the
    onCompletion
    argument of
    produce
    is marked internal api, and it is not possible to
    CoroutineStart.ATOMIC
    with
    produce
    , how can one make sure a given resource is always released?
    d
    e
    • 3
    • 10
  • p

    Paul Woitaschek

    10/30/2018, 9:03 PM
    When converting a listener to a channel is there a better way than creating a channel inside produce and then iterating it like here? https://github.com/Beepiz/BleScanCoroutines/blob/master/core/src/main/java/com/beepiz/bluetooth/scancoroutines/experimental/BleScanner.kt#L44
    l
    v
    • 3
    • 3
  • p

    Paul Woitaschek

    10/30/2018, 9:17 PM
    I tried to do the same with sensor manager - it feels kind of complicated: https://github.com/PaulWoitaschek/Voice/commit/58abc5302af30328e6f11593aed5deac78aa1e5b
    l
    • 2
    • 2
  • g

    groostav

    10/30/2018, 11:06 PM
    Hey gents, I'm writing a little adaptor for grpc (which, has anybody made this into a library?
    k-grpc
    ?
    grpc-k-extensions
    ?), my first implementation looked like this
    grpc_wapper_kt.kt
    o
    • 2
    • 1
  • k

    kevinherron

    10/30/2018, 11:37 PM
    is there a way to configure the thread names used by the underlying pools and executors for the coroutine dispatchers provided by stdlib?
    g
    • 2
    • 5
  • i

    ibash

    10/31/2018, 6:34 AM
    https://kotlinlang.slack.com/archives/C0922A726/p1540967451566300
    g
    • 2
    • 3
  • h

    Harun

    10/31/2018, 10:34 AM
    Before migrating from coroutines experimental, i was able to use the launch as in the above snippet. Trying to do the same on Kotlin 1.3 and am not able. What am i missing?
    -.kt
    g
    g
    a
    • 4
    • 18
  • d

    dave08

    10/31/2018, 1:38 PM
    Then
    var currWork: Job = null
    launch { if (cancelCurrWork) currWork?.cancel() }
    currWork = doWork()
    ?
    d
    j
    d
    • 4
    • 21
  • l

    louiscad

    10/31/2018, 3:00 PM
    It seems
    withContext
    doesn't throw any
    CancellationException
    before running the passed block even if the context is cancelled. I thought it checked before, and after running the passed block. Is this an intentional change, a doc misreading or a misunderstanding of the source code from me?
    e
    t
    • 3
    • 3
  • d

    deviant

    10/31/2018, 3:18 PM
    i've finally found how to disable IDE warnings:
    compileKotlin {
        kotlinOptions {
            freeCompilerArgs = ['-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi']
        }
    }
    🕵️‍♂️🏼 1
    d
    j
    +3
    • 6
    • 21
  • h

    hmole

    10/31/2018, 3:51 PM
    Hello. I'm trying to make 3 http requests concurrently and return single result(like rx
    zip
    ) with coroutines. Api calls are
    Deferred<T>
    with
    retrofit-coroutines-adapter
    . But they don't seem to execute in parallel. What am I doing wrong?
    m
    j
    +2
    • 5
    • 26
  • c

    christophsturm

    10/31/2018, 6:05 PM
    if i need a library that still uses the expermental coroutines packages, can i still upgrade to kotlin 1.3?
    o
    • 2
    • 1
  • f

    Felix

    10/31/2018, 9:00 PM
    A way to launch new coroutines inside a coroutine, without creating a new scope (i.e. using the current coroutine's scope), seems to be
    CoroutineScope(coroutineContext).launch {...}
    . 1) Is there a better way? 2) Is this a bad practice?
    e
    • 2
    • 3
  • f

    Felix

    10/31/2018, 9:09 PM
    I don't have a concrete reason, just exploring possibilities. However, an abstract example would be: if I want to explore some parallelism by launching children coroutines inside a coroutine, the immediate way seems to be by using a
    coroutineScope{ launch {...} launch {...}}
    . However,
    coroutineScope
    suspends until all the children coroutines are completed. Probably most of the times this is a good thing, however there may be situations where I want to continue without waiting for the child coroutines to end.
    m
    g
    u
    • 4
    • 13
  • t

    tuan.lam

    11/01/2018, 7:40 AM
    Hi everyone, I have a problem, pls help to clear it. How multi coroutines work in cpu?
    :stackoverflow: 4
    g
    • 2
    • 3
  • k

    Kulwinder Singh

    11/01/2018, 8:18 AM
    In android i am launching coroutine using
    launch
    builder but now inside this builder i'm confused with
    async
    ,
    withContext
    and
    coroutineScope
    like what is best for which situation? can please anybody tell me when to use one of them inside
    launch
    ?
    l
    f
    v
    • 4
    • 7
  • p

    Paul Woitaschek

    11/01/2018, 8:30 AM
    In all these coroutine talks they talk about fan-out fan-in like its a common term. What does that mean?
    d
    d
    • 3
    • 3
  • j

    julioyg

    11/01/2018, 8:48 AM
    Hi guys, is there any doc around on how to execute a suspend function from Java?
    g
    e
    • 3
    • 11
  • m

    Mark Gilchrist

    11/01/2018, 10:02 AM
    hi guys I have a coroutine base question on SO can I post it on here?
    e
    • 2
    • 1
  • m

    Mark Gilchrist

    11/01/2018, 10:04 AM
    https://stackoverflow.com/questions/53098975/mocked-suspend-function-returns-null-in-mockito
    v
    • 2
    • 5
  • m

    Mark

    11/01/2018, 12:22 PM
    when using
    produce{}
    for a finite sequence of items, the docs say to call
    SendChannel.close()
    to indicate no more items will be sent. But isn’t the common case for no more items to be sent once
    produce
    lambda has completed naturally? In which case, why is
    SendChannel.close()
    not done automatically?
    v
    • 2
    • 5
  • j

    Jonathan

    11/01/2018, 1:36 PM
    Why
    ReceiveChannel.toSet()
    and
    ReceiveChannel.toMap()
    are
    ObsoleteCoroutinesApi
    but
    ReceiveChannel.toList()
    is not?
    e
    d
    • 3
    • 10
  • r

    rocketraman

    11/01/2018, 5:03 PM
    Idiomatic way to add Coroutine scope to a function that is already an extension function of something else? Take it as a parameter?
    e
    z
    • 3
    • 7
  • r

    rocketraman

    11/01/2018, 5:07 PM
    Another question: why does
    CoroutineScope.writer
    et al in
    <http://kotlinx.coroutines.io|kotlinx.coroutines.io>
    take a
    coroutineContext
    ? Can't it get it from the receiver
    CoroutineScope
    ?
    z
    • 2
    • 3
Powered by Linen
Title
r

rocketraman

11/01/2018, 5:07 PM
Another question: why does
CoroutineScope.writer
et al in
<http://kotlinx.coroutines.io|kotlinx.coroutines.io>
take a
coroutineContext
? Can't it get it from the receiver
CoroutineScope
?
z

Zach Klippenstein (he/him) [MOD]

11/01/2018, 6:33 PM
Normally functions that do this add the passed-in context to the context from the scope, to allow you to easily override the context for the new coroutine without creating a new scope. Usually that context parameter is optional though, and I’m not sure why it wouldn’t be here. File a bug?
r

rocketraman

11/02/2018, 6:21 AM
I have seen that pattern before, and yup, I would have expected this parameter to be optional as well.
https://github.com/Kotlin/kotlinx-io/issues/18
View count: 3