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

    jkbbwr

    04/13/2017, 6:49 PM
    Damn this all looks really cool but im not a fan of a few of the design directions
    e
    • 2
    • 1
  • k

    kevinherron

    04/14/2017, 2:54 PM
    without something in the type signature or the language to force me to deal with exceptions, i accidentally don’t handle them sometimes
    a
    • 2
    • 1
  • n

    nimtiazm

    04/15/2017, 8:57 AM
    John Rose et al has announced recently that java will get fibers a.k.a coroutines ;)
    d
    s
    +2
    • 5
    • 22
  • e

    elizarov

    04/19/2017, 10:03 AM
    There is no much difference between coroutines and promises for simple stuff. Compare:
    promise.then {
        it.doSomething() 
    }
    with
    launch {
        promise.await().doSomething() 
    }
    This is quite a liberal example hand-crafted so that both direct usage of promise and coroutines somewhat match in readability. Coroutine benefits accrue with complex processing pipelines (do something async, then something else async, handle exceptions of multiple async actions in one place, etc).
    a
    • 2
    • 4
  • l

    louiscad

    04/19/2017, 1:40 PM
    It would require forcing type parameter to extend
    Any
    instead of default implicit
    Any?
    e
    • 2
    • 1
  • l

    louiscad

    04/19/2017, 1:42 PM
    I have a question about the
    invokeOnCompletion { ... }
    . It runs regardless of the fact that the coroutine was cancelled or just completed successfully, right?
    e
    • 2
    • 3
  • p

    Paul Woitaschek

    04/19/2017, 2:03 PM
    Am I the only one who thinks coroutines are kind of ... complicated?
    m
    d
    • 3
    • 3
  • e

    elizarov

    04/19/2017, 2:53 PM
    There is no reason to argue when every person has its own use-case in mind. Different use-cases are better suited for different solutions and tools. For those who say “ReactiveX is enough” I’d suggest to look at coroutine-based #ktor routing and try to figure out how ReactiveX would have been of any help there 😉
    👍 1
    d
    • 2
    • 4
  • d

    dg3feiko

    04/19/2017, 3:35 PM
    for JVM, I strongly recommend Quasar http://blog.paralleluniverse.co/2015/05/21/quasar-vs-akka/ for concurrent programming
    :trollface: 1
    e
    p
    • 3
    • 4
  • k

    kirillrakhman

    04/20/2017, 7:56 AM
    It's an Android app, I'm doing some async network requests and then I'm manipulation the UI. The network requests can throw `IOException`s or `HttpException`s so I need to catch them, otherwise the app will crash.
    e
    c
    • 3
    • 18
  • u

    umar

    04/21/2017, 8:34 PM
    Hi everyone. Do anyone know parallel sequence library based on coroutines?
    e
    • 2
    • 6
  • t

    thomasnield

    04/24/2017, 1:28 PM
    I'm curious what is the difference between lightweight threads and threads? I haven't really played with Qasar and I'm just starting to play with coroutines. What makes them less expensive? Are they just a better abstraction? Are they backed and distributed to traditional threads?
    d
    g
    • 3
    • 7
  • k

    kirillrakhman

    04/26/2017, 7:53 AM
    @gildor you've done the retrofit couroutine library. would you consider making one for okhttp?
    g
    u
    • 3
    • 5
  • g

    groostav

    04/26/2017, 8:08 AM
    @kirillrakhman I've written some kotlin-ish pseudo code here, I'd really appreciate you taking a look https://gist.github.com/Groostav/7e89dde503909a13d9ac21cd3c0f4fa2
    k
    • 2
    • 25
  • d

    deviant

    04/28/2017, 2:25 PM
    is there a way to do something like this?
    suspend val text = readFromFile()
    e
    • 2
    • 1
  • p

    pniederw

    05/03/2017, 11:21 PM
    are there any docs on coroutines performance? In particular, I’m trying to understand why nested suspending functions aren’t significantly more expensive than nested future-returning functions, due to the need to recreate the method stack on every resumption.
    e
    • 2
    • 1
  • p

    pniederw

    05/03/2017, 11:23 PM
    and are there any reasons why kotlin coroutines should have less overhead than quasar?
    e
    • 2
    • 1
  • e

    elizarov

    05/04/2017, 6:58 AM
    The other difference in implementation details concern state spilling. Quasar spills stack to heap only when suspension does happen. Kotlin spills the stack to heap before every invocation of
    suspend fun
    (this is covered in the spec quite well) in anticipation of suspension, even if that invocation will decide not to suspend. So here is the full table of differences:
    spill on suspend        restore on resume
    Quasar            LAZY                    EAGER
    Kotlin            EAGER                   LAZY
    You can interpret it in this way: Quasar is optimised for the code that rarely suspends, while Kotlin coroutines are optimised for the code that often suspends. This properly of Kotlin coroutines is not an accident, since they were originally optimised for an efficient implementation of
    generateSequence/yield
    pair that should work almost as fast as a manual implementation of the
    Sequence
    . However, we have a lot of room to tweak those performance trade-offs in future updates (even without breaking compatibility) as we get more data on how coroutines get actually used in the wild.
    👍 12
    :stackoverflow: 1
    k
    • 2
    • 1
  • o

    orangy

    05/04/2017, 10:03 AM
    You can ask question and reply to it yourself 🙂 I think that explanation like this should be stored on something more durable than Slack channel with message limit…
    e
    k
    +2
    • 5
    • 9
  • t

    tinycedar

    05/05/2017, 6:18 AM
    suspend fun RedisAsyncConnection<String, String>.getAsync(key: String): String = suspendCoroutine { cont -> cont.resume(this.get(key).get()) }
    e
    • 2
    • 1
  • w

    winteryoung

    05/06/2017, 5:06 AM
    Seems a similar topic has been discussed this morning. Hope it will be implemented sooner. 🙂
    e
    • 2
    • 1
  • a

    alband

    05/09/2017, 8:47 AM
    what is the reason for
    suspend
    not to be applicable on read-only (
    val
    ) property ?
    d
    • 2
    • 2
  • e

    elizarov

    05/12/2017, 2:31 PM
    @pawel.barszcz: You can implement that two-way logic easily if you need it. And much more. Here is an example impl: https://github.com/Kotlin/kotlin-coroutines/blob/master/examples/generator/generator.kt
    p
    • 2
    • 1
  • k

    kirillrakhman

    05/15/2017, 5:19 PM
    @gildor I'm playing around with retrofit coroutines and I noticed that the following trivial program never terminates. any ideas?
    fun main(args: Array<String>) = runBlocking(CommonPool) {
        val result = service.someCall().awaitResponse()
        println(result)
    }
    g
    j
    • 3
    • 14
  • g

    gildor

    05/15/2017, 7:17 PM
    You can implement retry with Retrofit and Okhttp using interceptors, so it’s possible to do for each instance of OkHttpClient
    s
    • 2
    • 2
  • g

    gildor

    05/15/2017, 7:50 PM
    @kirillrakhman I’ve commit first draft of okhttp library, not published yet, I’m on vacation now, maybe later - https://github.com/gildor/kotlin-coroutines-okhttp Also I investigate what can I do with WebSockets API of OkHttp and coroutines.
    k
    • 2
    • 2
  • j

    jw

    05/15/2017, 8:05 PM
    the API for both projects'
    Call
    type is unchanged from the .0 release to the current minor release with regard to what it takes to adapt
    e
    • 2
    • 1
  • k

    kirillrakhman

    05/17/2017, 1:29 PM
    try
    val Cached = Executors.newCachedThreadPool().asCoroutineDispatcher()
    
    class Foo {
        fun doBlocking(): Any {
            Thread.sleep(1000)
            return Any()
        }
    }
    
    suspend fun Foo.doAsync(): Any { 
        return async(Cached) {
            doBlocking()
        }.await()
    }
  • e

    elizarov

    05/18/2017, 9:28 PM
    @groostav with
    kotlinx-coroutines-jdk8
    you can write something like:
    val coercedResult = future { 
        try { result.await() } 
        catch(ex: Throwable) { 
            Thread.handleUncaughtException(ex)
            emptyList() 
        } 
    }
    😀 1
    g
    • 2
    • 23
  • k

    kirillrakhman

    05/19/2017, 11:27 AM
    is
    kotlin.coroutines=enable
    in the gradle.properties file not supported anymore?
    e
    • 2
    • 2
Powered by Linen
Title
k

kirillrakhman

05/19/2017, 11:27 AM
is
kotlin.coroutines=enable
in the gradle.properties file not supported anymore?
e

elizarov

05/19/2017, 12:55 PM
kirillrakhman: It should continue to work.
k

kirillrakhman

05/19/2017, 12:57 PM
ok, something is broken in AS 2.4P7 and 1.1.3-eap
View count: 2