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

    jimn

    08/11/2017, 3:22 AM
    hi, how do i approximate a functional parser framework that uses threadlocals .... so that a parser context that is declarative does not need to have explicit stackframe and input parameters clogging up the kotlin code?
    e
    • 2
    • 1
  • g

    gildor

    08/11/2017, 4:59 AM
    Actually, it depends what you want to achieve (is it in suspend context or not, do you really need different dispatchers for particular calls or not etc)
    a
    • 2
    • 2
  • j

    julienviet

    08/11/2017, 3:21 PM
    can you make this sync to central happen ?
    e
    • 2
    • 6
  • j

    jimn

    08/12/2017, 7:06 AM
    its kind of like i want to use a collection of dozens or possibly hundreds of lambdas which fire global events to indicate pass or fail in a grammar parse graph
    i
    • 2
    • 1
  • j

    julienviet

    08/14/2017, 10:23 AM
    I can’t find much documentation on coroutine cancellation, at least I don’t find anything in the coroutine KEEP, is there anything that documents it ?
    👍 1
    k
    e
    • 3
    • 5
  • j

    jimn

    08/14/2017, 7:02 PM
    will the llvm target support coroutines ?
    e
    • 2
    • 1
  • w

    wouterdoeland

    08/20/2017, 11:55 AM
    Hi! Sometimes it takes very very long to get into a coroutine. For example:
    <http://logger.info|logger.info>("command = start")
                        launch(CommonPool) {
                            <http://logger.info|logger.info>("in pool for start")
    I get the
    in pool for start
    message minutes later than
    command = start
    message. Am I not using coroutines correctly? I am running a lot of stuff in these launch(CommonPool) blocks.
    d
    • 2
    • 4
  • e

    ersin_ertan

    08/20/2017, 8:01 PM
    Is it correct to say that the execution order of multiple coroutines is non deterministic, while the execution within the coroutine lambda is deterministic?
    v
    • 2
    • 1
  • a

    alband

    08/21/2017, 8:27 AM
    anyone got news about this issue ? https://github.com/mockito/mockito/issues/1152 this is quite blocking to me.
    e
    • 2
    • 3
  • j

    jimn

    08/23/2017, 3:15 AM
    how do i support a declarative syntax such as:
    val terminal = any_of(seq(singleQuote, character, repeating(character), singleQuote), seq(doubleQuote, character, repeating(character), doubleQuote))
    ... and then wrap coroutines around the ctor params which are themselves functions which should be coroutines....
    • 1
    • 2
  • j

    johannes.lagos

    08/23/2017, 7:18 AM
    I'm experience that the
    await()
    on my coroutine doesn't wait to be done before it continue.
    g
    • 2
    • 20
  • j

    julienviet

    08/24/2017, 11:27 AM
    the example are I think confusing as they don’t show how you can write synchronous code with the select API, they just do print on the console
    e
    • 2
    • 1
  • x

    xanderblinov

    08/26/2017, 2:03 PM
    @stanislav.erokhin @cy @elizarov
    o
    • 2
    • 1
  • x

    xanderblinov

    08/26/2017, 2:42 PM
    as you know for java threads, even if you use synchronized block you need in volotile key world for variable
    e
    • 2
    • 3
  • t

    trubesv

    08/26/2017, 7:15 PM
    Hi all! I'm having trouble calling a function from a
    Coroutine
    that is inside a custom
    ViewHolder
    The function is not recognised, and when I put it in the
    ViewHolder
    class, of course I can't calll the `add`/`remove` functions anymore.. Could you point me in the right direction please? Here is the basic setup:
    class MyAdapter() : RecyclerView.Adapter<MyViewHolder>()
    {
        fun add() {}
        fun remove() {}
        [...]
    
        /* Custom ViewHolder */
        class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
        {
            fun bind(item: Item) = with(itemView)
            {
                /* Handle long click event on row*/
                isLongClickable = true
                onLongClick { function() } // I'M HAVING TROUBLE HERE (Unresolved reference)
           
                [...]
            }
        }
    
        /* How to call this? */
        fun function() {
            add()
            remove()
        }
    Thanks for the help! 🙂
    v
    r
    k
    • 4
    • 8
  • d

    dragas

    08/28/2017, 12:56 PM
    Is producer coroutine still held in
    CommonPool
    even after it has called
    close()
    on itself? For example
    fun doThings() : ProducerJob<Foo> = produce(CommonPool)
    {
       println("I am do things!")
       delay(1000)
       send(Foo())
       close()
    }
    e
    • 2
    • 2
  • b

    benfleis

    08/28/2017, 7:20 PM
    Perhaps I don’t know where to look, but I haven’t found any good info/indications about coroutines, and their use in production code, particularly in long-running services. I am aware that the 1.1 status of API is roughly “we don’t promise not to change”, but I am curious about the reliability and usage of it right now. Anybody have a clue, in the form of numbers, anecdotes, examples?
    e
    l
    • 3
    • 3
  • b

    benfleis

    08/29/2017, 7:32 AM
    yeah, i am less worried about the question of having to update code, and more about the realities of coroutines in long running services; I have no idea how much they’re being used in prod, and in particular, how much in services, as opposed to android (or what the differing qualities would be there).
    d
    • 2
    • 2
  • e

    elizarov

    08/29/2017, 2:53 PM
    @dragas You are definitely inventing your own code style, which makes your code unnecessary harder to read (it occupies way more vertical space than it should for such a simple code). That is the first thing that meets an eye.
    ➕ 2
    d
    j
    e
    • 4
    • 5
  • a

    anthonyeef

    08/30/2017, 8:18 AM
    Am I doing this correctly? I am trying to catch the exception if there is any occur when getting data from remote
    async(UI) {
        val fetchDataJob = bg {
            ColumnRepo.getFromRemote(22352581)
        }
    
        val data = fetchDataJob.await()
        info(data.id.toString())
        if (fetchDataJob.isCompletedExceptionally) {
            doSomeThingWithException(fetchDataJob.getCompletionException())
        }
    }
    g
    • 2
    • 4
  • g

    gildor

    08/30/2017, 8:27 AM
    You can just wrap
    fetchDataJob.await()
    to try/catch. If await fails (and will throw exception) your
    fetchDataJob.isCompletedExceptionally
    never be reached
    a
    • 2
    • 4
  • d

    Dalinar

    08/31/2017, 1:47 AM
    is supporting suspending getters something on the horizon? also, is there any workaround or we must completely avoid properties if we want the to do some suspendable calculations (for the "property")?
    d
    • 2
    • 2
  • e

    elizarov

    08/31/2017, 12:45 PM
    @dragas Can you, please, add a self-contained example that crashes?
    d
    • 2
    • 12
  • a

    andreasmattsson

    09/01/2017, 8:31 AM
    Hi! Cross-posting here from #kotlin-native : Any coroutine-gurus here than can help? I've wrapped a C-library method, that feeds values to a callback, in a kotlin method to capture the results (callback will be called multiple times) in a lambda. Basically called like this:
    library.invoke(arg) { value -> doSomething(value) }
    Now what I'd like to do is wrap this somehow so that instead of using a callback my wrapping method returns a Sequence (going from a push to a pull style API). My first attempt was to use buildSequence:
    buildSequence { library.invoke(arg) { value -> yield(value) } }
    But this gives
    Suspension functions can be called only within coroutine body
    . The Wrapping callbacks section in the documentation here looked promising: https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#wrapping-callbacks But as far as I can tell this
    suspendCoroutine
    trick only works if the callback is called only once by the library. Mine is called many many times, and I want to have a sequence where I can consume items one by one and not have to gather them in a list first. Channels looks like a good approach but AFAIK they are only available in the
    kotlinx.coroutines
    package that does not work in Kotlin Native. Any suggestions? Are there any "out of the box" or idiomatic solutions for this that don't involve manually implementing a producer/consumer pattern using C/threading concurrency stuff?
    g
    e
    • 3
    • 5
  • p

    pakoito

    09/03/2017, 5:44 PM
    does anyone have an example of starting a coroutine inside a suspendCoroutineOrReturn block?
    d
    • 2
    • 5
  • j

    jw

    09/05/2017, 3:33 PM
    It uses
    Thread.sleep
    though, so...
    u
    g
    • 3
    • 6
  • k

    kenkyee

    09/05/2017, 7:21 PM
    but when you do Observable.fromAsync (Rx1) or Observable.create(), you can set a cancellation callback. Seems a much cleaner way to get notified rather than having to check a flag in a loop for Kotlin coroutines
    e
    • 2
    • 2
  • q

    qwert_ukg

    09/06/2017, 3:00 AM
    does JetBrains use coroutines in production already?
    o
    • 2
    • 1
  • p

    pakoito

    09/06/2017, 8:56 AM
    @edwardwongtl We’re building one. It’s been working for a while and we’re nearing release in a couple of months.
    e
    k
    a
    • 4
    • 5
  • e

    elizarov

    09/06/2017, 12:18 PM
    We are working on curio-like I/O library. The prototype is already commited to
    develop
    branch. There are byte channels for suspendable reading/writing and later we’ll publish the whole sockets & http stack based on that.
    👍 5
    j
    j
    c
    • 4
    • 8
Powered by Linen
Title
e

elizarov

09/06/2017, 12:18 PM
We are working on curio-like I/O library. The prototype is already commited to
develop
branch. There are byte channels for suspendable reading/writing and later we’ll publish the whole sockets & http stack based on that.
👍 5
j

julienviet

09/06/2017, 12:33 PM
of which repo ?
e

elizarov

09/06/2017, 3:51 PM
https://github.com/Kotlin/kotlinx.coroutines/tree/develop/core/kotlinx-coroutines-io
j

jkbbwr

09/07/2017, 10:25 AM
Huh TIL the thing is about curio is that there is the scheduler and its use of "traps" its a really nice way to model explicit async code imo
c

christophsturm

09/07/2017, 11:14 AM
is it going to move to its own repo soon?
e

elizarov

09/07/2017, 11:22 AM
@jkbbwr Where I can learn more about it?
@christophsturm it will remain a part of kotlinx.coroutines for quite a while.
c

christophsturm

09/07/2017, 11:32 AM
ah because you are using it to drive the design of the coroutines api evolution?
e

elizarov

09/07/2017, 1:09 PM
Yes
View count: 3