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

    jw

    09/06/2017, 12:48 PM
    sad to see it's just nio's APIs
    o
    k
    +2
    • 5
    • 11
  • k

    kevinherron

    09/06/2017, 3:34 PM
    i have a project i’d like to prototype using the I/O library once there’s a socket backend
    o
    b
    • 3
    • 6
  • d

    deviant

    09/07/2017, 11:57 AM
    @gildor could you please explain why we need this extra code in each coroutine in the
    kotlin-coroutines-retrofit
    lib?
    private fun Call<*>.registerOnCompletion(continuation: CancellableContinuation<*>) {
        continuation.invokeOnCompletion {
            if (continuation.isCancelled)
                try {
                    cancel()       // why to cancel already cancelled coroutine?
                } catch (ex: Throwable) {
                    //Ignore cancel exception
                }
        }
    }
    g
    • 2
    • 2
  • g

    groostav

    09/08/2017, 9:58 PM
    regarding hot vs cold, there is no concept of a cold Channel is there? My best bet is to give something like a
    Provider<Channel>
    d
    e
    • 3
    • 2
  • e

    elizarov

    09/11/2017, 7:31 AM
    @jw A coroutines threading model is different from Rx threading model. In Rx the thread your code runs in is implicitly controlled by various onXXX operators up/down the stream, while in coroutines the thread (context) is explicitly specified for each coroutine. The only exception is
    Unconfined
    context, which leaves the thread “unspecified”.
    j
    • 2
    • 4
  • e

    elizarov

    09/11/2017, 12:06 PM
    @deviant
    EmptyCoroutineContext
    and
    Unconfined
    are virtually the same with the exception that
    Unconfined
    is designed to work with debugging facilities of
    kotlinx.coroutines
    (in debug mode you’ll get the id of the executing coroutine added to the thread name — wastes a lot of CPU, but simplifies debugging)
    d
    • 2
    • 7
  • j

    jw

    09/11/2017, 9:17 PM
    can we get something like
    ChannelIterable
    that has
    fun iterator(): ChannelIterator<T>
    ?
    o
    e
    • 3
    • 15
  • g

    gildor

    09/14/2017, 7:30 AM
    @anthonyandroid Please check this section of official coroutine guide - https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#concurrent-using-async Also you can check sample from kotlin-coroutines-retrofit (you can use this approach for any coroutine): https://github.com/gildor/kotlin-coroutines-retrofit#parallel-requests
    👏 1
    a
    • 2
    • 7
  • e

    elizarov

    09/14/2017, 7:48 AM
    Let me offer this conceptual model:
    launch
    is just like starting a new thread. If the code inside
    launch
    crashes with exception then it is considered “uncaught” exception and, generally, should crash your app (on Android that happens automatically). However, when you use
    async
    and the execution results with exception, then this exception gets stored inside the
    Deferred
    . It is your obligation to process it later. So: -
    launch
    - fire and forget, crash application on uncaught error; -
    async
    - launch and
    await
    for result later. You must
    await
    on a coroutine that you’ve created with
    async
    . You MUST NOT forget about the coroutine you’ve started with async.
    ❤️ 1
    👍 11
    d
    • 2
    • 9
  • g

    gildor

    09/14/2017, 8:13 AM
    It would be nice to have it in kdoc of launch: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/launch.html
    ➕ 3
    v
    e
    • 3
    • 7
  • e

    elizarov

    09/14/2017, 9:15 AM
    The only reasons we don’t have a wiki for
    kotlinx.coroutines
    is because we are still evolving it and bits of syntax and behavior might change from release to release. It is easier to keep docs versioned together with sources (both guides and kdocs). You cannot do this with wikis. Risks are high you will end up with outdated wikis (for example,
    CoroutineScope.context
    was deprecated recently, renamed to
    coroutineContext
    — it was easy to push it into all the guides and kdocs with a single commit)
    v
    • 2
    • 2
  • e

    elizarov

    09/15/2017, 4:57 PM
    📣 I’m working on a change to the behavior of parent-child relations between coroutines for the upcoming release of
    kotlinx.coroutines
    . Parent will always wait for its children to complete. Details of the change are here: https://github.com/Kotlin/kotlinx.coroutines/issues/125 Please, comment if you don’t think it is a good idea.
    👍 12
    d
    • 2
    • 2
  • m

    mingkangpan

    09/17/2017, 9:46 PM
    oh, never seen some non blocking IO actually, what would it look like for example on android?
    g
    • 2
    • 1
  • r

    raulraja

    09/17/2017, 9:53 PM
    Not sure if Kotlin has something similar to
    blocking
    but if not you should probably create a Pool that is tunned up for this type of ops usually DB calls, network IO, etc...
    e
    • 2
    • 1
  • e

    elizarov

    09/18/2017, 7:45 AM
    @kevinherron It will not deadlock. Cancelling parent immediately cancels children, it then waits for them to complete. Moreover, since children receive from parent’s channel in your case, if parent terminates normally, then it closes its own channel (first!), thus aborting all receiving children, and then waits for its children to complete.
    k
    k
    • 3
    • 4
  • d

    deviant

    09/18/2017, 3:25 PM
    just curious: what is the best way to convert
    Channel
    into
    Sequence
    ? is it possible? something like that
    produce<Int>{
     send(1)
     send(2)
     send(3)
    }
    .asSequence()  // some suspendable helper?
    .filter {it==1}
    j
    e
    h
    • 4
    • 5
  • g

    Gary Tierney

    09/18/2017, 11:29 PM
    In a way, yes, the code I'm targeting are game scripts which maintain a lot of state about their last execution which results in lots of tiny complex state machines. This reduces that complexity significantly!
    o
    • 2
    • 2
  • e

    elizarov

    09/19/2017, 7:18 PM
    @dragas There is no reason to use coroutines unless you have any suspending (async) function. If it all just CPU-bound, the coroutines offer a little help/improvement. For CPU-bound task, like parallel collection processing, Java8 streams work best. Coroutines are designed for tasks that wait for something most of the time.
    d
    d
    • 3
    • 2
  • k

    kingsley

    09/22/2017, 11:43 AM
    There are 2 sides to your question. Can we unit test
    launch
    ? Yes, we can. You simply run it within a
    runBlocking
    and
    await
    it’s completion (or termination as the case may be) However the
    UI
    makes it difficult to unit test without bringing all the platform dependency with it. I would abstract this part out instead, to make it easy to swap with a non-platform dependent coroutineContext
    d
    • 2
    • 1
  • e

    elizarov

    09/22/2017, 8:09 PM
    You create a channel and run
    N
    worker coroutines that all take tasks from this channel and do your http calls. The number of coroutines you have limits the number of concurrent HTTP requests without having you think about threads at all. In fact, if your HTTP library is truly async, they can all simply run a single thread, yet still giving you control over maximal concurrency.
    o
    g
    • 3
    • 5
  • k

    kirillrakhman

    09/24/2017, 6:07 PM
    @Deactivated User you should create an issue
    👍 1
    d
    • 2
    • 4
  • k

    kioba

    09/25/2017, 3:52 PM
    As long as coroutines are experimental i would not recommend. But If youchose to go with coroutines without rx i would love to hear about the experience and you should definately write a blog about it 🙂
    d
    j
    • 3
    • 14
  • g

    gildor

    09/25/2017, 11:34 PM
    https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#concurrent-using-async
    d
    • 2
    • 2
  • g

    gildor

    09/26/2017, 7:20 AM
    It’s not a good idea to use CommonPool for blocking IO operations
    d
    • 2
    • 1
  • p

    Paul Woitaschek

    09/26/2017, 7:22 AM
    Do I need to call bindImage().await?
    g
    • 2
    • 1
  • e

    elizarov

    09/26/2017, 7:35 AM
    You can always add
    run(UI)
    for them just to make sure they are on the right thread (it will not switch if you invoke them from the right thread). Ideally, we should have tooling where you’d annotate your UI functions with
    @UI
    (or even better — make this annotation inferred by looking at their code and seeing that they use some other UI-thread-only functions) and then it would warn you if you try to use them from the wrong context…. Just an idea.
    g
    • 2
    • 3
  • p

    Paul Woitaschek

    09/26/2017, 7:36 AM
    Ah nice, got confused with the autocompletion to
    kotlin.run
    e
    • 2
    • 1
  • v

    voddan

    09/26/2017, 10:51 AM
    Where was the thread on changing
    run
    builder function function to a less confusing name? Gonna vote on that
    o
    • 2
    • 1
  • d

    dave08

    09/26/2017, 2:56 PM
    message has been deleted
    • 1
    • 1
  • p

    pablisco

    09/26/2017, 11:17 PM
    Does anybody know if it’s possible to create a property (delegated or not) that suspends (with coroutines) in the getter?
    g
    • 2
    • 3
Powered by Linen
Title
p

pablisco

09/26/2017, 11:17 PM
Does anybody know if it’s possible to create a property (delegated or not) that suspends (with coroutines) in the getter?
g

gildor

09/27/2017, 1:48 AM
https://youtrack.jetbrains.com/issue/KT-15555
p

pablisco

09/27/2017, 6:02 AM
Cool! Good to know that some people is also interested :) maybe when coroutines come out fully
g

gildor

09/27/2017, 6:04 AM
Roman, main author of coroutines and kotlinx.coroutines created this issue itself 🙂 I don’t think that it’s related to experimental status because “experimental” is more about backward compatibility warranties
➕ 2
View count: 4