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

    deviant

    03/20/2017, 9:17 AM
    launch(context + job1 + job2){}
    is it possible to use 2 different parents to control child lifecycle? well, i know it's not. but what best way to achieve such functionality?
    k
    h
    • 3
    • 17
  • k

    kingsley

    03/20/2017, 8:25 PM
    private val callbackContext = ...
    
    fun request(...) {
      pendingJob?.cancel()
      
      pendingJob = launch(callbackContext) {
        delay(DEBOUNCE_PERIOD)
        ...
        suspendingFun()
        ...
      }
    }
    
    suspend fun suspendingFun(...) {
      someApi().await()
      ...
    }
    This used to work fine in version 0.12. Currently on version 0.14, the launch block doesn't seem to execute more than once anymore. Not sure what the problem is
    e
    • 2
    • 3
  • o

    oshai

    03/22/2017, 6:28 AM
    scala on the other hand works with the parent interface: CompletionStage https://github.com/scala/scala-java8-compat/blob/master/src/main/scala/scala/compat/java8/FutureConverters.scala which looks on a first glimpse as a perferred approach?
    o
    • 2
    • 1
  • d

    dstarcev

    03/23/2017, 1:05 PM
    what is similar to C#‘s
    Task.WhenAll()
    in kotlin?
    d
    k
    • 3
    • 3
  • s

    sreich

    03/24/2017, 4:41 PM
    Trying not to shoehorn coroutines where they don't fit well (especially since I'm unfamiliar with them) Do coroutines sound like a good fit for that?
    g
    • 2
    • 2
  • o

    orangy

    03/24/2017, 8:29 PM
    Tweet to Baruch…
    i
    • 2
    • 1
  • n

    nquinn

    03/25/2017, 9:10 PM
    https://kotlinlang.slack.com/archives/coroutines/p1490224611686044
    g
    • 2
    • 3
  • u

    uli

    03/31/2017, 7:42 AM
    Wouldn't it be preferable to have the Delay interface not depend on java.util.concurrent.TimeUnit?
    ☝️ 1
    e
    • 2
    • 8
  • u

    uli

    03/31/2017, 7:48 AM
    suspend fun delay(time: Long, unit: TimeUnit = TimeUnit.MILLISECONDS) {
            require(time >= 0) { "Delay time $time cannot be negative" }
            if (time <= 0) return // don't delay
    Wouldn't it be more comfortable to not have require(time >= 0) Especially, as the implementation for time < 0 follwos right on the next line
    e
    • 2
    • 15
  • m

    menegatti

    03/31/2017, 10:53 AM
    I was trying to keep coroutine related code away from the presenter, but let me try your thing
    k
    • 2
    • 5
  • u

    uli

    04/02/2017, 7:42 PM
    Don't you have to await the future? I would guess, something like this will throw:
    fun main(args: Array<String>) {
        val f = future {
            throw RuntimeException("Hello!")
        }
        f.await()
    }
    i
    a
    • 3
    • 7
  • u

    uli

    04/02/2017, 9:05 PM
    What would be your suspending function then? I would say putting runBlocking around non suspending code is a noop. What are you trying to achieve?
    i
    • 2
    • 4
  • u

    uli

    04/04/2017, 6:53 AM
    @Ian Here comes the code. You provide inBackground(), main demonstrates how your users should apply it:
    fun inBackground(doWork: suspend () -> Unit) {
        launch(CommonPool) {
            try {
                doWork()
            } catch (t: Throwable) {
                // Do Logging, rethrow, ...
            }
        }
    }
    
    fun main(args: Array<String>) {
        inBackground {
            println("before delay")
            delay(100)
            println("after delay")
        }
        Thread.sleep(100000)
    }
    Ideally, inBackground() should be inline. But that is not yet supported.
    👍 3
    i
    • 2
    • 1
  • v

    voghdev

    04/05/2017, 10:24 AM
    Does anyone know a way to invoke a method that contains a coroutine from a Unit Test? for example calling this initialize() here from a test: https://github.com/voghDev/HelloKotlin/blob/coroutines/app/src/main/java/es/voghdev/hellokotlin/UserDetailPresenter.kt (found Tony Owen's workaround but I'd prefer another solution: https://medium.com/@tonyowen/android-kotlin-coroutines-unit-test-16e984ba35b4)
    e
    • 2
    • 6
  • n

    nfrankel

    04/06/2017, 7:35 AM
    i’ve played around and i’ve that now:
    var results = listOf<SearchResult>()
            runBlocking<Unit> {
                results = providers.map {
                    async(CommonPool) {
                        it.search()
                    }
                }.map { it.await() }
            }
            return results
    a
    • 2
    • 1
  • i

    Ian

    04/06/2017, 2:31 PM
    @nekoinemo Is there a way to have it block until it hits the first suspension, as
    thread {}
    appears to do?
    e
    k
    • 3
    • 4
  • i

    Ian

    04/06/2017, 2:58 PM
    @nekoinemo Sorry if this is what you meant, but what I’m hoping for is something that will block only until the first suspend is hit, then it will return to the calling code - but the remainder of the block will be executed once the suspend resumes
    e
    • 2
    • 2
  • s

    sreich

    04/07/2017, 4:44 PM
    how does one use the
    context
    field? seems like a map but i don't get what the key is
    e
    • 2
    • 1
  • s

    sreich

    04/07/2017, 5:33 PM
    also i'm trying to use
    newFixedThreadPoolContext
    to create a fixed amount of threads to run my function on..but i think i need to know the thread id it's running on (0 or 1..n)
    e
    • 2
    • 5
  • g

    groostav

    04/08/2017, 8:57 PM
    I guess I get a performance win if, rather than use the blocking
    readMessage
    method, I write a suspending function on top of the event-callback for https://msdn.microsoft.com/en-us/library/windows/desktop/aa365788(v=vs.85).aspx
    e
    • 2
    • 1
  • y

    yasyd

    04/09/2017, 10:24 AM
    Ok thanks
    e
    • 2
    • 3
  • r

    rafal

    04/10/2017, 8:07 AM
    Hello everyone. Do you know whether there Is any built-in mechanism to emulate rx's `BehaviorSubject`/`ReplaySubject` on `Channel`s ?
    e
    k
    • 3
    • 17
  • n

    nimtiazm

    04/10/2017, 9:26 AM
    I want a simple future library that would carry the response from a callback and outside the block I have future.get which awaits
    e
    • 2
    • 2
  • v

    vonox7

    04/11/2017, 6:16 PM
    @elizarov We already use runAsync1 for many months in production and have seen that the CPU load is more a theoretical than practial problem. I really like the way with Executors (never thought of it), thanks for this input! But of course we would like to switch to coroutines. So probably we have a blocking problem. We will investigate further why our backend doesn't work when we change runAsync1 with runAsync2.
    e
    • 2
    • 1
  • k

    kingsley

    04/11/2017, 8:20 PM
    Is there a way to run suspending code in blocking mode reliably?
    runBlocking
    seems to give up immediately it encounters an interrupt, leaving the suspending function in a possibly corrupt mode. Or maybe I'm only overthinking this? 🤔
    e
    • 2
    • 6
  • w

    wineluis

    04/13/2017, 9:52 AM
    it looks more complicated
    e
    n
    • 3
    • 3
  • d

    dmitry.petrov

    04/13/2017, 1:42 PM
    In fact, I think C2 can do that, too, when the stars are right.
    e
    • 2
    • 2
  • e

    elizarov

    04/13/2017, 5:26 PM
    They are serializable right now. You can convert them to byte array with your favorite serialization framework. You just have to provide serializable context and make sure that all the locals are serializable. Then you can parcel the resulting byte array. I'm curios as to what is your use-case, though?
    a
    • 2
    • 9
  • j

    jkbbwr

    04/13/2017, 5:30 PM
    Is coroutines in 1.1?
    e
    • 2
    • 1
  • n

    nimtiazm

    04/13/2017, 5:50 PM
    you’ll have to add this repo
    url "<https://dl.bintray.com/kotlin/kotlin-eap-1.1>"
    i
    • 2
    • 1
Powered by Linen
Title
n

nimtiazm

04/13/2017, 5:50 PM
you’ll have to add this repo
url "<https://dl.bintray.com/kotlin/kotlin-eap-1.1>"
i

ilya.gorbunov

04/13/2017, 6:15 PM
jcenter
is enough
View count: 3