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

    otakusenpai

    10/17/2018, 9:00 PM
    Hello how could I make a function repeatable after a period of time using coroutines?
    s
    e
    • 3
    • 8
  • d

    danny

    10/18/2018, 12:27 AM
    What's the state of
    <http://Dispatchers.IO|Dispatchers.IO>
    ? I'm seeing different behavior to the documentation, and some scheduling weirdness
    d
    e
    • 3
    • 22
  • o

    oshai

    10/18/2018, 5:35 AM
    I am writin a lib: https://github.com/jasync-sql/jasync-sql and just started to use coroutines internal (not in exposed api). Since this is new I am not using experimental packages. I wonder how this affects lib users? They will not be able to use it if they are using experimental coroutines?
    g
    e
    • 3
    • 34
  • s

    SUPERCILEX

    10/18/2018, 5:59 AM
    Unanswered questions I couldn't find in docs:
    g
    • 2
    • 1
  • s

    SUPERCILEX

    10/18/2018, 5:59 AM
    https://twitter.com/SUPERCILEX/status/1052757672385163264
    e
    • 2
    • 11
  • s

    SUPERCILEX

    10/18/2018, 5:59 AM
    https://twitter.com/SUPERCILEX/status/1052757673253339136
    e
    • 2
    • 2
  • s

    SUPERCILEX

    10/18/2018, 5:59 AM
    https://twitter.com/SUPERCILEX/status/1052757674025082881
    l
    • 2
    • 7
  • s

    SUPERCILEX

    10/18/2018, 6:02 AM
    https://twitter.com/SUPERCILEX/status/1052757674981380096
    • 1
    • 3
  • s

    SUPERCILEX

    10/18/2018, 6:06 AM
    https://twitter.com/SUPERCILEX/status/1052757676805869568
    e
    • 2
    • 8
  • m

    marcinmoskala

    10/18/2018, 12:34 PM
    https://github.com/JetBrains/kotlinconf-app/pull/53
    v
    • 2
    • 2
  • d

    dave08

    10/18/2018, 2:21 PM
    Where to
    supervisorScope { }
    and
    coroutineScope { }
    get their
    CoroutineScope
    from?
    m
    s
    v
    • 4
    • 20
  • d

    dave08

    10/18/2018, 3:43 PM
    I have a
    produce { }
    that sends download status to a notification service, so if there's an exceoption I'd like to be able to send an error message. It looks like
    try { } catch() { }
    is unreliable (https://github.com/Kotlin/kotlinx.coroutines/issues/361), and installing a
    CoroutineExceptionHandler
    on
    produce
    I won't be able to get to its channel to report status... is there any better way to do this?
    v
    • 2
    • 2
  • s

    SUPERCILEX

    10/18/2018, 4:51 PM
    @elizarov Would you be interested in this contribution?
    public suspend inline fun <T : Closeable?, R> T.useCancellably(
            crossinline block: (T) -> R
    ): R = suspendCancellableCoroutine { cont ->
        cont.invokeOnCancellation { this?.close() }
        use(block)
    }
    e
    • 2
    • 21
  • d

    danny

    10/18/2018, 7:14 PM
    Are workers as a concept planned for the stable release of coroutines, or coming later?
    n
    e
    • 3
    • 10
  • o

    otakusenpai

    10/19/2018, 3:22 AM
    Is something wrong with my code here(doing java.io.File writing in a coroutine)
    class AsyncLogger : AbstractLogger {
    
        constructor(filepath: String,name: String) : super() {
            var file = File(filepath)
            file.mkdirs()
            filename = "$filepath/$name"
            file = File(filename)
        }
    
        suspend fun log(toLog: Boolean,msg: String) = coroutineScope {
            GlobalScope.launch {
                if (toLog)
                    writeToFile(msg)
            }
        }
    
        suspend fun log(toLog: Boolean,toFile: Boolean,msg: String) = coroutineScope {
            GlobalScope.launch {
                if(toLog)
                    when(toFile) {
                        true -> writeToFile(msg)
                        false -> writeToFile(msg)
                    }
            }
        }
    
        override suspend fun writeToSTDOUT(msg: String) =
                println(message = "[${Thread.currentThread().name}]: $msg")
    
        override suspend fun writeToFile(msg: String): Job = coroutineScope {
            GlobalScope.launch {
                val stream = RandomAccessFile(filename, "rw")
                val channel = stream.channel
                var lock: FileLock? = null
                try {
                    lock = channel.tryLock()
                } catch (e: OverlappingFileLockException) {
                    stream.close()
                    channel.close()
                }
                stream.writeBytes(msg + '\n')
                lock?.release()
                stream.close()
                channel.close()
            }
        }
    
    }
    n
    h
    a
    • 4
    • 12
  • o

    otakusenpai

    10/19/2018, 6:05 AM
    Can you give me an example particular to this use case ? @elizarov
    e
    d
    • 3
    • 4
  • s

    SUPERCILEX

    10/19/2018, 7:44 AM
    What is the purpose of
    join
    now that the outer scope will wait for all functions launched within to complete?
    e
    • 2
    • 16
  • o

    otakusenpai

    10/19/2018, 7:48 AM
    I'm using ticker function to create a repeating task which repeats after 1 min. I have the receive part of the code done. But the problem is in the apply part. Where do I sent the function which calls the apply code of the ticker? The ticker itself is running inside a while loop.
    d
    • 2
    • 2
  • o

    otakusenpai

    10/19/2018, 7:55 AM
    @SUPERCILEX I can't delay inside the main thread because it should wait for 1 minute, which is a long time for the app(its networked)
    e
    s
    • 3
    • 8
  • j

    Joris PZ

    10/19/2018, 8:20 AM
    I see this remark often, and there's something here I don't understand. If I call
    .receive()
    on a non-blocking NIO channel, it will immediately return with either some available data, or
    null
    . So if I were to use this in a coroutine, I'd have to do this in an infinite loop, no? Something like:
    while(true) {
       channel.receive(buffer)
       // handle data if available
    }
    If I were to implement it like this, wouldn't that make the CPU load 100%? Or am I supposed to implement a delay here to prevent this?
    e
    d
    • 3
    • 7
  • a

    alex009

    10/19/2018, 9:06 AM
    @elizarov hi! i see coroutines start 1.0.0 RC versions, so in 1.0.0 release version not planned multithreaded support?
    e
    • 2
    • 7
  • d

    Daniel Tam

    10/19/2018, 11:56 AM
    where can I find the source for suspendCoroutine? Am I looking in the wrong repo?
    d
    • 2
    • 1
  • r

    Ruckus

    10/19/2018, 5:58 PM
    Is there any way to have set-like functionality for a channel? Basically a way for a channel to not accept a value if it already has that value in its "queue".
    e
    • 2
    • 2
  • m

    myanmarking

    10/19/2018, 6:15 PM
    guys, what is the best way to wait all results of async calls inside a for loop ?
    a
    n
    g
    • 4
    • 8
  • m

    myanmarking

    10/19/2018, 6:15 PM
    i can’t use a parent job, its deprecated. i cant find the new way
    e
    • 2
    • 5
  • d

    Damien

    10/19/2018, 8:16 PM
    How to convert those functions with a complete listener to a suspend function?
    -.kt
    z
    s
    • 3
    • 4
  • p

    pabl0rg

    10/20/2018, 10:44 AM
    Might anything here be worth considering before 1.0 release? http://250bpm.com/blog:137
    e
    • 2
    • 1
  • r

    raulraja

    10/20/2018, 8:52 PM
    Hi!, After migrating to 1.3-RC I get this compiler warning:
    w: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
    I’m not sure where to disable it as I don’t have manual flags passed to the compiler process. Any help is appreciated, thanks!
    e
    • 2
    • 3
  • o

    oshai

    10/20/2018, 8:58 PM
    I am thinking about writing actors library, do you think it is required?
    d
    d
    k
    • 4
    • 7
  • n

    Nikky

    10/21/2018, 11:22 AM
    found this: https://gist.github.com/elizarov/69ff0cf47d9ffe013bc6c1aeaf5af552
    k
    • 2
    • 1
Powered by Linen
Title
n

Nikky

10/21/2018, 11:22 AM
found this: https://gist.github.com/elizarov/69ff0cf47d9ffe013bc6c1aeaf5af552
k

kevinherron

10/22/2018, 4:21 AM
I threw this together a couple months ago: https://gist.github.com/kevinherron/5a895911a45eb5752ff247a205d618b7 (@dave08 too)
View count: 2