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

    elizarov

    12/20/2017, 7:32 AM
    I do believe that documentation for
    getCancellationException
    explains the purpose and behavior for this method quite well. Maybe we should rename it to reduce ambiguity and prevent its abuse? https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-job/get-cancellation-exception.html
    l
    • 2
    • 3
  • l

    lovis

    12/21/2017, 8:59 AM
    The docs say:
    >> IMPORTANT NOTE: We advise library authors to follow the same convention: add the “experimental” (e.g. com.example.experimental) suffix to your packages exposing coroutine-based APIs so that your library remains binary compatible. When the final API is released, follow these steps:
    copy all the APIs to com.example (without the experimental suffix), keep the experimental package around for backward compatibility. This will minimize migration issues for your users.
    👍🏽 3
    l
    e
    • 3
    • 4
  • s

    shayla

    12/21/2017, 4:56 PM
    Interesting, we are also working on a Bluetooth library!
    l
    o
    d
    • 4
    • 18
  • l

    louiscad

    12/21/2017, 10:55 PM
    Am I right thinking `BroadcastChannel`s are something similar to what we could call "observables"? Note that I have near-zero knowledge in RxJava so I'm not comparing it to RxJava specific `Observable`s.
    e
    • 2
    • 1
  • l

    louiscad

    12/22/2017, 11:27 PM
    Is there a way to communicate from one component to another one (both having different lifecycles), through coroutines, a frequently updating
    Int
    value (progress of an upload I get from a callback) without incurring memory allocation nor autoboxing on each update? Note that I'm fine bridging the communication using a global property or a property on a singleton (an
    object
    )
    ❓ 1
    d
    • 2
    • 1
  • b

    bj0

    12/23/2017, 12:24 AM
    if a
    BroadcastChannel
    doesn't have any subscribers, will `send`s to it suspend or be dropped?
    e
    • 2
    • 3
  • n

    napperley

    12/24/2017, 10:31 PM
    If threads were used instead then all CPU cores would be maxed out and memory usage would spiral out of control, which would lead to the dreaded OOM (Out Of Memory error) scenario.
    l
    s
    • 3
    • 9
  • d

    dh44t

    12/25/2017, 1:16 AM
    Silly question, why I can use
    ReceivingChannel
    in a
    for
    loop? Is it an iterable? I don't see anything on its hierarchy
    l
    d
    • 3
    • 3
  • b

    bj0

    12/26/2017, 5:41 PM
    i'm getting some inconsistent crashes when I try to use
    launch {}
    in a button click handler:
    java.lang.NullPointerException: Attempt to invoke interface method 'kotlin.coroutines.experimental.CoroutineContext$Element kotlin.coroutines.experimental.CoroutineContext.get(kotlin.coroutines.experimental.CoroutineContext$Key)' on a null object reference
    d
    • 2
    • 22
  • q

    qwert_ukg

    12/27/2017, 8:10 AM
    This code works fine, but maybe here is something not so good. I mean the way of making async request.
    g
    • 2
    • 2
  • g

    gildor

    12/27/2017, 8:29 AM
    also there is a feature request to simplify such code like your https://github.com/Kotlin/kotlinx.coroutines/issues/171
    👍 1
    q
    • 2
    • 10
  • q

    qwert_ukg

    12/28/2017, 5:31 AM
    I have several methods with async call, should i create local pool inside each method, or will be better if i make it one per class instance ?
    g
    • 2
    • 4
  • k

    kingsley

    12/28/2017, 2:21 PM
    How is this any better than https://github.com/gildor/kotlin-coroutines-retrofit And, the
    onX
    functions look weird. Personal opinion though
    ☝️ 1
    k
    • 2
    • 1
  • k

    kingsley

    12/28/2017, 2:23 PM
    Also. There is coroutines adapter that already supports coroutines natively with Retrofit https://github.com/JakeWharton/retrofit2-kotlin-coroutines-adapter
    ☝️ 3
    k
    • 2
    • 1
  • j

    jw

    01/01/2018, 4:11 AM
    That still doesn't do exactly what a throttle should, but you're reinforcing that the answer is that I need to build it myself.
    d
    l
    • 3
    • 13
  • a

    asad.awadia

    01/02/2018, 1:11 PM
    Hmm - i m still unsure of how coroutines will be used in real life situations.. other than syntactic sugar to avoid call back hell - is there anything it provides?
    l
    h
    • 3
    • 16
  • v

    vitrox1

    01/02/2018, 3:37 PM
    Hello guys anyone here knows if there’s a way to test coroutines with espresso I mean is not detecting the async process as usually espresso does, so is going forward into the testing code without await ?
    l
    s
    • 3
    • 10
  • b

    bj0

    01/02/2018, 8:07 PM
    @louiscad I was thinking about testing out your lib since including the whole RxJava library just to receive BLE data is overkill, and it's also giving me trouble
    l
    s
    • 3
    • 12
  • p

    pakoito

    01/02/2018, 9:41 PM
    ^^^ kotlinx.coroutines is also large, not sure if as much as Rx but it wasn’t a trivial lib
    l
    • 2
    • 2
  • j

    jw

    01/03/2018, 5:18 AM
    https://github.com/Kotlin/kotlinx.coroutines/issues/171
    👍 5
  • b

    bj0

    01/03/2018, 8:46 PM
    if I create a
    Channel
    in a coroutine, and I want that channel closed when the coroutine is canceled, is the only way to catch the
    CancellationException
    ?
    l
    • 2
    • 4
  • b

    bartosz.malkowski

    01/04/2018, 10:50 AM
    I'm not sure if creating Handler object is best way to do that
    v
    • 2
    • 4
  • e

    enleur

    01/04/2018, 12:22 PM
    suspend fun call(): Element {
        return suspendCancellableCoroutine { continuation ->
            client.request(Element("request"), object : Handler {
                override fun success(response: Element) {
                    continuation.resume(response)
                }
    
                override fun error(response: Element) {
                    continuation.resume(response)
                }
            })
        }
    }
    v
    • 2
    • 2
  • b

    bartosz.malkowski

    01/04/2018, 1:42 PM
    I found three possible solutions https://gist.github.com/bmalkow/7b8adc12f725018581c4cd8ad404e9d1
    e
    • 2
    • 1
  • b

    bdawg.io

    01/04/2018, 11:58 PM
    That would instead result in code written like
    try {
        val element = xmpp.request(Element("request"))
        println("Received element: $element")
    } catch (error: FailureException) {
        println("oops... error! ${error.condition}")
    } catch (timeout: TimeoutException) {
        println("timeout")
    }
    d
    r
    • 3
    • 3
  • p

    paulblessing

    01/05/2018, 6:46 PM
    class ResourceManager<out T>(private val resource: T, readConcurrency: Int) {
    
      private val readWriteLock = ReentrantReadWriteLock()
      private val readContext = newFixedThreadPoolContext(readConcurrency, "reader")
      private val writeContext = newSingleThreadContext("writer")
    
      suspend fun <R> read(block: (T) -> R): R = withContext(readContext) {
        readWriteLock.readLock().withLock { block(resource) }
      }
    
      suspend fun <R> write(block: (T) -> R): R = withContext(writeContext) {
        readWriteLock.writeLock().withLock { block(resource) }
      }
    
    }
    Going this way seems to do the trick pretty well, though I still have a dirty feeling about using the locks since they'll block. Maybe that's OK since these are all background threads but I haven't fully convinced myself that there aren't gotchas.
    r
    • 2
    • 1
  • j

    Jan Koprowski

    01/06/2018, 9:40 PM
    How to start with Kotlin Coroutines? Tutorial https://kotlinlang.org/docs/tutorials/coroutines-basic-jvm.html does not compile gradle script after modification under IntelJ IDEA 2017.3.2. Any ideas?
    d
    g
    • 3
    • 11
  • j

    jw

    01/08/2018, 3:28 AM
    CompletableFuture, RxJava, Project Reactor, etc.
    q
    • 2
    • 1
  • s

    streetsofboston

    01/09/2018, 8:58 PM
    Hi everyone, This goes back to my earlier post about being able to quickly unit-test functions that execute coroutines. Especially if these functions have timeouts or delays and you’d like to run each of your tests in milliseconds and not seconds, I wrote a
    CoroutineContext
    that allows you to do so. It is very much like the RxJava’s
    TestScheduler
    and its methods
    triggerActions
    ,
    advanceTimeBy
    , etc. It does so by implementing a Coroutine Dispatcher (for speeding up (virtual) time) and a Coroutine Exception Handler (for testing thrown exceptions). The main
    TestCoroutineContext
    class and some unit-tests can be found here: https://gist.github.com/streetsofboston/6ea225c61566e6d349883082fbb9f020
    👍🏽 2
    🤘 2
    • 1
    • 1
  • l

    louiscad

    01/10/2018, 4:28 PM
    Despite this being accidental, I think I'll take advantage of this until
    nosuspend
    or similar becomes a thing, to prevent accidental bad usage of the APIs I designed (to use
    Bundle
    on Android with properties on a shared
    object
    )
    d
    • 2
    • 6
Powered by Linen
Title
l

louiscad

01/10/2018, 4:28 PM
Despite this being accidental, I think I'll take advantage of this until
nosuspend
or similar becomes a thing, to prevent accidental bad usage of the APIs I designed (to use
Bundle
on Android with properties on a shared
object
)
d

dave08

01/10/2018, 9:12 PM
I think a clearly kdoc'ed function is worth more than such a hack that might risk being "fixed" soon, people have been known to exclude libs dependencies to get higher versions of others to avoid issues with tons pf alrady written code... but I personally always ctl-q any fun I'm not sure about...
Although I agree it's tasty to find loopholes like this 🍔
l

louiscad

01/10/2018, 10:19 PM
Of course a proper KDoc is important, but I don't see how this would stop working. There's no way a
crossinline
lambda could allow suspension implicitly when you think about it.
d

dave08

01/11/2018, 3:48 AM
Hacks are hacks, even if it would work, the fact that someone else wouldn't understand how the code actually works is already code smell. I found myself looking at source code of well documented functions to reason about some case the devs didn't think about to see if it would work in my situation. Using undocumented/unintended functionality prevents that. You can disagree, but I know alot of people stay away from libs that do too much 'magic'.... 😉
l

louiscad

01/11/2018, 7:33 AM
Who said preventing suspension would prevent to document it?
d

dave08

01/11/2018, 8:26 AM
Didn't mean that, but I guess each one with their style and habits 🙂
View count: 5