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

    snrostov

    10/24/2017, 11:01 AM
    just curious: what is the "kotlinx-coroutines-debug" gradle plugin?
    e
    • 2
    • 5
  • p

    pakoito

    10/25/2017, 4:47 PM
    executing one after another, like with andThen
    d
    • 2
    • 1
  • e

    elizarov

    10/26/2017, 8:29 AM
    invokeOnCompletion
    is mostly designed for internal machinery. Franky, I think it should be somehow “hidden” from API to discourage its use from a general-purpose application code, but I don’t know what would be best way to do it. You should define
    then
    to get this “chained” style of programming like this:
    fun <T, U> Deferred<T>.then(next: suspend (T) -> U): Deferred<U> = async { next(await()) }
    We might include it in the future updates of
    kotlinx.coroutines
    for convenience.
    👍 1
    e
    • 2
    • 4
  • o

    Olekss

    10/26/2017, 11:04 AM
    Hey I guess I am stupid. How do I get coroutines lib in simple JVM project. Simplest InetlliJ with simplest Kotlin plugin 1.5.x and I can't import coroutines, and I don't see the lib anywhere...
    m
    • 2
    • 1
  • l

    Luis

    10/26/2017, 11:06 PM
    Can someone explain the reasoning behind this: "In particular, it means that a parent coroutine invoking join on a child coroutine that was started using launch(coroutineContext) { ... } builder throws CancellationException if the child had crashed, unless a non-standard CoroutineExceptionHandler if installed in the context." ? It seems unintuitive at best. It makes something like this:
    val outerJob = launch(CommonPool) {
        val inner1 = launch(coroutineContext) { /* blah */ }
        val inner2 = launch(coroutineContext) { /* blah */ }
        // do more stuff
        select<Unit> {
            // These lines will actually throw a CancellationException if either of the inner jobs are completed exceptionally!!!
            inner1.onJoin { val reason = inner1.getCompletionException(); /* blah */ }
            inner2.onJoin { val reason = inner2.getCompletionException(); /* blah */ }
        }
    }
    
    // Here I can call `outerJob.cancel()` to cancel everything
    very awkward to write
    e
    • 2
    • 4
  • z

    zarkopafilis

    10/27/2017, 8:58 AM
    Hello, does anyone know best case register # swaps that need to happen in order to switch from 2 coroutines multiplexed on the same running thread?
    e
    • 2
    • 2
  • h

    hydrakecat

    10/27/2017, 12:04 PM
    Hmm. I thought I could pass a continuation to the other and receive its continuation using createCoroutine. Isn't it possible?
    e
    • 2
    • 2
  • f

    Fré Dumazy

    10/27/2017, 12:16 PM
    Anybody having this issue on Android with Dexguard and kotlin coroutines? Unexpected error while computing stack sizes: Class = [kotlinx/coroutines/experimental/JobSupport] Method = [notifyHandlers(Lkotlinx/coroutines/experimental/JobSupport$NodeList;Ljava/lang/Throwable;)V] Exception = [java.lang.IllegalArgumentException] (Stack size becomes negative after instruction [164] pop in [kotlinx/coroutines/experimental/JobSupport.notifyHandlers(Lkotlinx/coroutines/experimental/JobSupport$NodeList;Ljava/lang/Throwable;)V])
    e
    • 2
    • 7
  • l

    littlelightcz

    10/27/2017, 4:55 PM
    Hi everybody, is it possible to execute a blocking IO operation (such as HTTP GET request) in a coroutine and make it suspend instead of blocking the thread?
    d
    • 2
    • 1
  • e

    elizarov

    10/27/2017, 5:57 PM
    @littlelightcz You’ll need to offload your blocking ops to a thread-pool. First, define a pool:
    val ioPool = newThreadPoolContext(n, "ioPool")
    Then you can wrap you IO operations into
    run(ioPool) { ... }
    . This will be a suspending operations from the invoker stand-point, the actual execution happening in the thread pool you’ve defined, so that the invoker thread (UI thread, of some other event thread like netty or vert.x) is not blocked.
    l
    s
    • 3
    • 4
  • o

    Olekss

    10/31/2017, 8:44 AM
    Hey. Question. Because coroutines at the end of the day call "continuation.setValue()" how it is organised on the stack. Wouldn't it end on stackOverflowException ? If I would implement CPS using kotlin I would end up with full stack? Can I do CPS in kotlin, or I need to play carefully with tale call optimization?
    e
    • 2
    • 5
  • m

    Marc Knaup

    10/31/2017, 1:12 PM
    Would it make sense to add coroutines support to a (streaming) JSON library? (+ wouldn’t turning all reads/writes into suspending functions slow down things a lot?)
    e
    • 2
    • 2
  • e

    elizarov

    11/01/2017, 9:54 PM
    What kind of thoughput you are looking for? A number of small http requests/sec or a number of bytes/sec downloading some big data?
    s
    • 2
    • 3
  • d

    dave08

    11/01/2017, 10:02 PM
    Is there some kind of
    produce { }
    for a
    BroadcastChannel
    ?
    e
    • 2
    • 3
  • d

    dave08

    11/01/2017, 10:09 PM
    Oh, I thought I'd have to do that, I just wondered if I was missing something or it would be included eventually... Also, how does one make a class out of
    actor { }
    and still be thread safe, can the class member vars be used or do they have to be contained in the
    actor { }
    function? And there must be an actor val to keep and return the actor.. one can't call send straight from the class. It would be nice to be able to derive from an actor abstract class...
    e
    • 2
    • 4
  • r

    rocketraman

    11/01/2017, 10:43 PM
    @SerGnat Try asking over on #ktor -- they are working on a pure-coroutine based http client to go along with their (experimental) pure coroutine based server backend
    s
    • 2
    • 1
  • t

    Tristan Caron

    11/04/2017, 2:09 PM
    Yes, but I cannot do

    http://reactivex.io/documentation/operators/images/S.PublishSubject.png▾

    h
    • 2
    • 7
  • d

    deviant

    11/04/2017, 4:27 PM
    use
    BroadcastChannel
    ➕ 5
    t
    • 2
    • 1
  • c

    crypto

    11/05/2017, 1:50 AM
    are kotlin coroutines still "experimental"? is there are a timeline for when people should actually use them?
    p
    • 2
    • 2
  • r

    raniejade

    11/06/2017, 11:23 AM
    Hi! Why is something like this not possible?
    class F {
        suspend fun CoroutineScope.process() {
    
        }
    }
    
    fun main(args: Array<String>) {
        launch {
            val f = F()
            // unresolved reference
            f.process()
        }
    }
    m
    • 2
    • 6
  • j

    jw

    11/07/2017, 12:59 AM
    there doesn't seem to be a cancelation hook when building a
    Deferred
    (via
    CompletableDeferred
    ). Is there something else that offers this callback?
    e
    • 2
    • 7
  • e

    elizarov

    11/07/2017, 4:45 PM
    https://stackoverflow.com/questions/46872242/how-to-exponential-backoff-retry-on-kotlin-coroutines/46890009
    👍 7
    f
    • 2
    • 9
  • k

    krenvpravo

    11/07/2017, 9:28 PM
    Is there idiomatic way to enforce JVM to do happens-before when nested coroutine returns to parent one? Performance overhead is acceptable.
    e
    • 2
    • 3
  • d

    deviant

    11/09/2017, 6:33 PM
    i have got weird behavior with
    delay
    on different platforms: while
    delay(Long.MAX_VALUE)
    works as expected in
    javafx
    desktop project (infinite delay) in android this line does nothing. but this one works:
    delay(Long.MAX_VALUE / 2)
    and i have no clue why
    e
    • 2
    • 6
  • e

    elizarov

    11/14/2017, 4:27 PM
    @Fré Dumazy Use
    Mutex
    f
    • 2
    • 6
  • s

    sailxjx

    11/15/2017, 8:24 AM
    I read these messages into a concurrent queue, and another thread (this is handled by the connect framework) will poll this queue and release the memory.
    sleep
    can avoid putting too many messages in the queue.
    u
    • 2
    • 1
  • s

    sailxjx

    11/15/2017, 8:54 AM
    Did you mean this:
    while (queue.size < 10000) {
            queue.add(element)
        }
  • s

    sailxjx

    11/15/2017, 8:54 AM
    Then how to come back into the while loop?
    g
    • 2
    • 10
  • n

    neil

    11/16/2017, 10:26 PM
    Is it possible to use coroutines with Kotlin/JS yet?
    b
    e
    • 3
    • 3
  • m

    marcinmoskala

    11/17/2017, 7:33 AM
    Is there any road map when coroutins will be allowed in common modules?
    g
    • 2
    • 3
Powered by Linen
Title
m

marcinmoskala

11/17/2017, 7:33 AM
Is there any road map when coroutins will be allowed in common modules?
g

gildor

11/17/2017, 10:12 AM
So coroutines not allowed in common modules? You cannot have
expect suspend fun
or just
suspend fun
?
m

marcinmoskala

11/17/2017, 11:13 AM
I can have suspend modifier in common modules but i believe that there is no coroutines library that can be used in common modules.
g

gildor

11/17/2017, 12:04 PM
Yes, but you can provide platform specific implementation, for js you probably need only wrapper for Promise and have suspend API
View count: 2