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

    uli

    12/06/2018, 5:21 PM
    @zokipirlo see the above thread, this code is broken no matter if contains is thread safe or not. think about this scenario:
    launch(ioContext) {
    	if (!mutableList.contains(something)) {
    		modifyActor.send(Add(something))
    	}
    }
    launch(ioContext) {
    // Actor has not yet processed the 'Add' message, because it was busy processing other requests
    	if (mutableList.contains(something)) {
    		//We will not get here
    		modifyActor.send(Remove(something))
    	}
    }
    z
    • 2
    • 2
  • d

    danny

    12/06/2018, 7:09 PM
    Any one else notice that
    CoroutineScheduler
    seems far too conservative about parking threads?
    v
    • 2
    • 10
  • r

    Rohan Maity

    12/07/2018, 4:38 AM
    Limit-Breaker: I was Reading about Coroutines in Kotlin "Kotlin coroutines are stackless , they don't have their own stack" "Threads are managed by OS and Coroutines managed by Users " What does this mean ? How Kotlin coroutines manages to unblock thread while suspending the functions ?
    b
    d
    • 3
    • 2
  • l

    louiscad

    12/07/2018, 10:53 AM
    Hi, I'm using kotlinx.coroutines with TornadoFx and the JavaFx artifact, and it worked fine, but today, it is not working but showing this in the logs:
    java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize
    (without cause logged). What could be the issue?
    v
    • 2
    • 7
  • p

    pablisco

    12/07/2018, 2:21 PM
    Good asynchronous people. Do we have a way to not use the Android Dispatcher for
    Dispatchers.Main
    when running on the test configuration (e.g. Unit tests)
    s
    v
    • 3
    • 6
  • m

    mbonnet

    12/07/2018, 2:49 PM
    Hi everyone, I’m having a bit of trouble with
    runBlocking
    and CoroutineScopes. I want to launch a coroutine in a scope with a combined
    Job
    for this coroutine to run until the job is cancelled. It works fine, but I would like to wrap it in a
    runBlocking
    (for unit tests purposes), but unfortunately the
    runBlocking
    doesn’t wait for the inner launch... Do you have any idea why ? Or how could I make it work somehow ?
    -.kt
    s
    • 2
    • 6
  • t

    Tolriq

    12/08/2018, 4:39 PM
    Have anyone noticed / faced this https://github.com/Kotlin/kotlinx.coroutines/issues/878 ? And eventually have an answer about how to bypass that slow init by statically creating our own Android dispatcher?
    g
    • 2
    • 1
  • a

    Alexey Pushkarev

    12/08/2018, 10:02 PM
    Hi, folks. I've just wrapped android billing into coroutines https://github.com/lion4ik/BillingCoroutines . I would appreciate your code review. Feel free to come up with ideas and issues. 🙂
    b
    d
    • 3
    • 5
  • m

    marekabaffy

    12/09/2018, 4:58 PM
    Hey. I’m going through the Coroutines docs and I’m a bit confused about the
    .cancelAndJoin()
    method. What is it good for? Why would I want to wait until the coroutine actually finishes the cancellation? I bet there is a pretty clear use case, but I just can’t see it.
    d
    b
    r
    • 4
    • 3
  • d

    dewildte

    12/09/2018, 10:12 PM
    Is anyone using Coroutines for Event Sourcing?
    l
    p
    • 3
    • 3
  • f

    Fabio Tudone

    12/10/2018, 11:25 AM
    Hi, is there any chance some kind of a reconstructed stack will be available in debug when stopping at a breakpoint in a coroutine? I guess specialized tooling will be required for that, is that right?
    c
    v
    • 3
    • 2
  • c

    chi

    12/10/2018, 12:13 PM
    Is it recommended to use coroutine methods marked with
    ObsoleteCoroutinesApi
    on our production apps? I'll like to use something around actors but worried about this annotation
    z
    g
    • 3
    • 3
  • g

    goldin

    12/10/2018, 1:24 PM
    Hi. I want to send data from one application point to another. I would like to use Channels for this. I use RendezvousChannel, but I always need to consumeEach so that I can receive updates on the next data transfer. In the documentation, the consumeEach method is marked as @ObsoleteCoroutinesApi. Maybe there is another way to get data?
    g
    • 2
    • 2
  • e

    edwinRNDR

    12/10/2018, 2:17 PM
    Can I have airhorns go off next time I accidentally use
    Thread.yield()
    instead of
    kotlin.coroutines.yield()
    ?
    📯 1
    😁 1
    m
    • 2
    • 2
  • g

    goldin

    12/10/2018, 10:27 PM
    Hi. I used channels to transfer data from one application point to another (From one screen to another). When I call send and receive for the first time, everything works fine, but if I try to re-do send for the same channel, I can’t get the data by calling the receive method. I found a solution that needs to use consumeEach. And the truth is, if you use it, then when you re-send, the receive method returns new data. In this regard, the question is, what is the fundamental difference of consumeEach from other functions: consume, first, last and others. I give an example code
    -.kt
    d
    z
    +2
    • 5
    • 19
  • s

    spierce7

    12/11/2018, 3:02 AM
    I have this warning all over the place polluting our build logs, to the point where circleci is making me download our build logs because they are too long:
    This declaration is experimental and its usage should be marked with '@kotlinx.coroutines.ExperimentalCoroutinesApi'
    Is there a way I can declare that we are using experimental coroutines api in the
    build.gradle
    , and thus get rid of all these warnings everywhere? Or am I forced to go to every file, and explicitly annotate it?
    g
    b
    d
    • 4
    • 21
  • g

    gattacus

    12/11/2018, 3:09 PM
    What is the best/official way to write a custom MainCoroutineDispatcher? I wrote one for SWT but requires use of internal and experimental API
    m
    v
    • 3
    • 8
  • z

    zak.taccardi

    12/11/2018, 6:51 PM
    Good or bad idea to use
    <http://Dispatchers.IO|Dispatchers.IO>
    when reading from Android's shared preferences?
    s
    • 2
    • 1
  • s

    spierce7

    12/11/2018, 9:28 PM
    When I add the following to all my submodules:
    tasks.withType(KotlinCompile) {
        kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"]
    }
    I notice I get the following error in modules that don't use coroutines at all:
    e: Experimental API marker kotlinx.coroutines.ExperimentalCoroutinesApi is unresolved. Please make sure it's present in the module dependencies
    Anyone know of a fix?
    g
    • 2
    • 6
  • r

    Rohan Maity

    12/12/2018, 1:03 AM
    Hello ! Can somebody tell the difference between Async/Await in C# , JS and Async coroutines in Kotlin. I read the docs of both (Async/await in c# & Async in Kotlin ) . Both lets you do the asynchronous programming without blocking the thread. So except the syntax . Is there any difference? Is there any upper hand of Async coroutine in Kotlin
    s
    g
    k
    • 4
    • 21
  • s

    Slackbot

    12/12/2018, 11:55 AM
    This message was deleted.
    t
    m
    b
    • 4
    • 7
  • i

    IAmRasputin

    12/12/2018, 7:28 PM
    Does
    runBlocking
    exist for the sole purpose of bridging non-blocking with blocking code? If I have a java application that depends on a Kotlin library, would I be able to have the library support coroutines by wrapping the API functions with
    runBlocking
    , or are there other gotchas I need to know so the java application can take advantage of asynchronous code?
    s
    • 2
    • 3
  • s

    streetsofboston

    12/12/2018, 8:55 PM
    Question about CoroutineDispatchers and resuming suspension points: Say a coroutine has a context with the
    <http://Dispatchers.IO|Dispatchers.IO>
    which is backed by a pool of threads, let’s say “Thread-1” through “Thread-64". When a suspension point in a suspend function is reached while running in “Thread-4”, does the function always resume in the same thread, “Thread-4", or could it resume in any of the other threads of the thread-pool of
    <http://Dispatchers.IO|Dispatchers.IO>
    (it could be “Thread-35”)? I think it is the last option (could be in the other threads of the dispatcher), but I’m not sure … 🙂
    d
    • 2
    • 3
  • p

    Paul Woitaschek

    12/13/2018, 6:14 AM
    Can we escalate this? https://github.com/Kotlin/kotlinx.coroutines/issues/858 I have a LOT of crashes
    v
    • 2
    • 2
  • k

    Kulwinder Singh

    12/13/2018, 9:40 AM
    i'm paginating list and loading 5 items each time recyclerview scrolled to last , then using
    coroutine
    i'm getting more data for each item from network like below
    private fun onItemsLoaded(videosList: List<BaseVideo>) {
            uiScope.launch {
                val videoAndData = getUserDataForEachVideo(videosList)//suspending function
                adapter.addData(videoAndData)
            }
        }
    so here everytime whenever new 5 items loaded then
    new
    coroutine
    is created, so here over the time it will increase created coroutines , i know that coroutines are light weight but is there any other way to solve this problem where i can create a single coroutine and then run my code inside that coroutine instead of creating new coroutine everytime
    s
    i
    • 3
    • 2
  • a

    acando86

    12/13/2018, 1:08 PM
    What's the best way to keep draining continuously a receivechannel, cancel whatever task the receiver is doing (if any) and start processing the latest messages as soon as they reaches the channel?
    d
    • 2
    • 6
  • m

    Marc Knaup

    12/13/2018, 4:03 PM
    Is there a quick way to create a
    ReceiveChannel
    from an
    Iterable
    ? à la
    fun <E> Iterable<E>.toChannel() =
    	GlobalScope.produce { forEach { send(it) } }
    m
    d
    • 3
    • 3
  • m

    Michal Fudala

    12/13/2018, 5:02 PM
    I'm trying to understand coroutines and I have a question: why does
    c2
    method hang here ?
    file.kt
    d
    g
    • 3
    • 45
  • b

    bdawg.io

    12/14/2018, 12:37 AM
    I created a library for using coroutines with AWS SDKs. Any code reviews/input would be appreciated! https://github.com/bradynpoulsen/aws-sdk-kotlin-coroutines/
    d
    • 2
    • 5
  • g

    groostav

    12/14/2018, 12:42 AM
    oh my goodness, well my first run in with
    operator fun invoke
    confusion, kotlin coroutine code:
    public fun <R> start(start: CoroutineStart, receiver: R, block: suspend R.() -> T) {
            initParentJob()
            start(block, receiver, this)
        }
    that
    start
    call is actually
    start.invoke(block, receiver, this)
    , it is not calling a superclass overload of
    start
    .
    b
    • 2
    • 3
Powered by Linen
Title
g

groostav

12/14/2018, 12:42 AM
oh my goodness, well my first run in with
operator fun invoke
confusion, kotlin coroutine code:
public fun <R> start(start: CoroutineStart, receiver: R, block: suspend R.() -> T) {
        initParentJob()
        start(block, receiver, this)
    }
that
start
call is actually
start.invoke(block, receiver, this)
, it is not calling a superclass overload of
start
.
b

bdawg.io

12/14/2018, 12:44 AM
Kotlin has some very strong operators. I often find myself using Go To Declaration (Cmd/Ctrl+B) to discover where items came from
g

groostav

12/14/2018, 1:02 AM
problem with
operator fun invoke
is that the thing you have to control-click on (ctrl+B on) is the parenthesis
b

bdawg.io

12/14/2018, 1:35 AM
It's the same as plus, minus, times, inc, get, or any other operator
View count: 3