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

    viniciuslrangel

    10/21/2018, 10:07 PM
    Hi, how should I "await" for a standard Java Future inside a suspending function?
    e
    • 2
    • 4
  • t

    tapchicoma

    10/22/2018, 6:55 AM
    Last line returns
    true
    , but I suppose it should be
    false
    . Is it a bug, or right behavior?
    -.kt
    e
    • 2
    • 7
  • d

    dstarcev

    10/22/2018, 9:20 AM
    But it creates a new scope isn't it?
    j
    g
    • 3
    • 41
  • d

    dave08

    10/22/2018, 10:21 AM
    Why does this test fail?
    val progress = Channel<Long>(Channel.CONFLATED)
    			val progressList = GlobalScope.async { progress.toList() }
    
    			runBlocking {
    				val progressResult = (0L..20L step 2).onEach { progress.offer(it) }
    				progress.close()
    
    				assertThat(progressResult.toList()).toBe(progressList.await())
    			}
    progressList
    is []...
    g
    • 2
    • 20
  • a

    adibfara

    10/22/2018, 11:16 AM
    is there a way to override Dispatchers.UI on unit tests in android? it's trying to use Looper.getMainLooper() which is a stubbed method
    g
    z
    • 3
    • 5
  • n

    Nikky

    10/22/2018, 11:36 AM
    compile("something>name:version") { exclude(name = "excludedDependency") }
    a
    • 2
    • 10
  • l

    louiscad

    10/22/2018, 11:41 AM
    @adibfara You can see how I did it for unit tests in the AndroidX Lifecycle integration PR in kotlinx.coroutines repo.
    a
    v
    • 3
    • 5
  • l

    louiscad

    10/22/2018, 12:41 PM
    Yes @robin, you can do it this way:
    coroutineScope {
        val daemonLikeJob = launch { while (true) /* Do sth until everything is done */ }
        coroutineScope {
            launch { /* do work */ }
            launch { /* do work */ }
        }
        daemonLikeJob.cancel()
    }
    r
    • 2
    • 8
  • m

    myanmarking

    10/22/2018, 1:49 PM
    e: java.lang.IllegalStateException: failed to analyze: java.lang.ArrayIndexOutOfBoundsException
    	at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:125)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:441)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:101)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1020)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:101)
    	at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1062)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1019)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:440)
    	at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
    	at sun.rmi.transport.Transport$1.run(Transport.java:200)
    	at sun.rmi.transport.Transport$1.run(Transport.java:197)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
    v
    • 2
    • 1
  • p

    patjackson52

    10/22/2018, 2:24 PM
    Are there any libraries yet to support common operators on channels? I am referring to Rx-type operators. There is a good article here with several examples. Seems like these could be shared in a library/libraries ( https://github.com/Kotlin/kotlinx.coroutines/blob/master/reactive/coroutines-guide-reactive.md)
    g
    • 2
    • 4
  • s

    Schadenfreude

    10/22/2018, 2:27 PM
    Hey guys, any coroutine gurus around who can help me out with something?
    c
    l
    +2
    • 5
    • 12
  • e

    enleur

    10/22/2018, 8:33 PM
    Looking for an advice on limiting concurrency. My problem is that I want to limit parallel running coroutines per some token(user, credentials, whatever) created on demand. Current implementation works, but not sure about it: https://gist.github.com/enleur/4bdd04b0e2c54b94f84a2ca62ca9b6ac
    d
    g
    • 3
    • 4
  • n

    nwh

    10/22/2018, 9:01 PM
    Why isn't
    withContext
    an extension on
    CoroutineScope
    ? Don't `launch`/`async` do more than just switch context?
    e
    • 2
    • 1
  • e

    elect

    10/22/2018, 9:41 PM
    trying to play with coroutines in 1.3 190 I get:
    Class 'kotlinx.coroutines.BuildersKt__Builders_commonKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler Class 'kotlinx.coroutines.CoroutineStart' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler Class 'kotlinx.coroutines.Job' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler Class 'kotlinx.coroutines.Job' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
    e
    • 2
    • 34
  • s

    spierce7

    10/22/2018, 10:10 PM
    In the RC it appears that
    newSingleThreadContext()
    has been removed. What should I be using instead?
    v
    v
    d
    • 4
    • 7
  • s

    spierce7

    10/22/2018, 10:51 PM
    Is there a better way to create a
    CoroutineContext
    than this? I used to be able to do
    CoroutineContext(Dispatcher)
    , but that doesn't seem to work anymore.
    • 1
    • 1
  • s

    spierce7

    10/23/2018, 3:14 AM
    I see there is a private API to create a context that reuses threads from the Default dispatcher, but limits it's parallelism to a single thread, i.e.
    LimitingDispatcher
    . Is this supported in a public API yet?
    e
    • 2
    • 2
  • s

    Schadenfreude

    10/23/2018, 10:00 AM
    Hey guys, I’m trying to write a simple coroutine to await a callback and return a value, but for some reason my code hangs and the response never comes. Here’s the gist: https://gist.github.com/Schadenfeude/8d0ccb88eb1b874d4e3cbf43327fe266 The last log I see is the one on line 19
    Log.d("BillingManagerProvider", "suspendCoroutine: startConnection")
    g
    • 2
    • 8
  • d

    deviant

    10/23/2018, 3:56 PM
    I've updated to
    1.0.0-RC1
    and now all my actors and channels marked as
    obsoleted api
    . What apis should we use instead?
    l
    • 2
    • 5
  • r

    rocketraman

    10/23/2018, 5:12 PM
    I have a database DAO from which I want to return a
    Sequence
    . However, I also want to close the db cursor when the sequence has finished consuming. Is this a valid approach?
    suspend fun findSomethings(...): Sequence<Something> {
      val cursor = ...
      return sequence {
        cursor.use {
          yieldAll(cursor.iterator())
        }
      }
    }
    d
    • 2
    • 4
  • s

    spierce7

    10/23/2018, 7:25 PM
    I'm seeing some issues with the given proguard file for latest version kotlinx.coroutines for Android. Any idea where I can find a proper pro-guard definition?
    l
    j
    • 3
    • 5
  • g

    gildor

    10/24/2018, 3:26 AM
    We started migration of our Android apps to Structured Concurrency implementation from kotlionx.coroutines (before we used own solution for that) and now I have question about CoroutineScope. Looks that for any UI component SupervisorJob is the best choice (it’s even mentioned on Coroutines guide, see https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/exception-handling.md#supervision), because you usually don’t want to cancel all the jobs is one of them failed on your UI component, this is especially important for
    async
    builder, because you handle result only when call
    await
    and don’t want to cancel all other coroutines and especially CoroutineScope of this UI component if one of our async jobs is failed, we can actually handle error when call await() And you need non-supervisor Job and scope only in case if you want to run a few operations in parallel and want to cancel them if one of them failed, but it’s specific and explicit case, at least in usual UI development So I have 2 points here: 1. Should coroutine guide recommend to use SupervisorJob for all UI components and not Job (what is now standard in documentation, for example check
    CoroutineScope
    docs which use Job in Android Activity). Otherwise it can cause a lot of very subtle bugs when you use CoroutineScope for UI development. 2. We need some easy way to start non-supervisor scope. Now the only way to do that is
    CoroutineScope(coroutineContext + Job())
    which is quite wordy way. maybe make sense to change
    coroutineScope
    default implementation and create new Job instance if outer context contains SupervisorJob If it make sense for someone, I would happy to create an issue and contribute, but maybe I missed some important use cases there
    i
    l
    +4
    • 7
    • 47
  • s

    sdeleuze

    10/24/2018, 10:32 AM
    @elizarov Watching

    https://www.youtube.com/watch?v=nKJbDYRsO0s▾

    , I am wondering if in long term future (let say Java 17 LTS since there is now a release each 6 months) it would make sense to think about Coroutines that would run on fibers (1 coroutine = 1 fiber) on the JVM to improve monitoring, debuggability, maybe performances. Any thoughts?
    v
    e
    • 3
    • 7
  • f

    fabianterhorst

    10/24/2018, 10:47 AM
    which repository url do i have to include to use coroutines version 1.0.0-rc1? Im not able to resolve it with
    maven { url "<https://dl.bintray.com/kotlin/kotlinx/>" }
    0.30.2-eap13 works just fine.
    v
    • 2
    • 2
  • k

    kirillrakhman

    10/24/2018, 1:42 PM
    @elizarov and everybody here: Do you think there is value in educating devs about the difference between - async as in OS-level async IO and - async as in doing a blocking call on a thread pool ? Both approaches unblock the calling (main) thread but I think the scaling characteristics are way different. Maybe it's not that important on a client but on the server you should be able to get way more concurrency using true OS-level asynchronicity which requires the proper libraries.
    👍 4
    g
    c
    +2
    • 5
    • 18
  • l

    lukaswelte

    10/24/2018, 1:47 PM
    When using a DB connection pool like HikariCP. Should one opt for
    <http://Dispatchers.IO|Dispatchers.IO>
    or a
    newFixedThreadPoolContext
    with the number of threads being the max DB pool size?
    e
    z
    • 3
    • 2
  • j

    Jaroslav

    10/24/2018, 2:20 PM
    I’m trying to make something similar to what is done in kotlinconf app - https://github.com/JetBrains/kotlinconf-app/blob/master/konfios/konfswift/ui/UI.swift but the problem is, there is no such class
    Kotlinx_coroutines_core_nativeCoroutineDispatcher
    in my ios framework. I’m using 1.0.0-RC1 coroutines. Maybe it changed the name or something?
    v
    e
    • 3
    • 4
  • l

    louiscad

    10/24/2018, 2:22 PM
    Before structured concurrency, such code would run properly:
    launch {
        val someWorkAsync = async {
            throw CustomException()
        }
        delay(100)
        try {
            someWorkAsync.await()
        } catch (e: CustomException) {
            println("Handled it! $e")
        }
    }
    If I understood correctly, now, the whole scope is cancelled, even though the exception is handled properly when calling
    await()
    . How can I get the previous behavior? Create a
    Job
    that has scope's job as parent, and use it for
    async(…) { … }
    ?
    m
    v
    e
    • 4
    • 7
  • d

    dave08

    10/24/2018, 5:06 PM
    Iterable.asReceiveChannel()
    was deprecated (in 0.30.2) contrary to the other channel operators that were just marked obsolete. Any reason why? Even Rx has such adapters, and this could come in handy in Unit testing for mocking...
    e
    • 2
    • 1
  • b

    bolot

    10/24/2018, 9:36 PM
    Has anybody run into an issue
    kotlin.Result cannot be cast to MyType
    ? I'm trying to use
    Result
    with LiveData, doing something like this:
    liveData.value = runCatching { useCase().await() }
    , which is then used in
    liveData.observe
    as
    result.onSuccess { } .onFailure { }
    (Kotlin version 1.3.0-rc-190)
    g
    a
    • 3
    • 6
Powered by Linen
Title
b

bolot

10/24/2018, 9:36 PM
Has anybody run into an issue
kotlin.Result cannot be cast to MyType
? I'm trying to use
Result
with LiveData, doing something like this:
liveData.value = runCatching { useCase().await() }
, which is then used in
liveData.observe
as
result.onSuccess { } .onFailure { }
(Kotlin version 1.3.0-rc-190)
g

gildor

10/24/2018, 11:15 PM
Maybe this issue https://youtrack.jetbrains.com/issue/KT-27105
There are still some known issues with Result
Or that https://youtrack.jetbrains.com/issue/KT-27586
b

bolot

10/24/2018, 11:21 PM
Thank you!
Exactly the same issue. I'll use my own, non-inline Result class for now. Thanks again!
a

amatkivskiy

11/25/2018, 10:02 AM
Seems that this is more related to inline classes issue rather then to specific Result class.
💯 1
View count: 5