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
rx
  • r

    Rok Koncina

    04/15/2019, 12:28 PM
    I'm trying to create a continuous stream of items where I'd always get the last one (aka. cache) using the BehaviorSubject (or ReplySubject) but whenever the api call stream terminates, so does my main stream. How can I prevent that? One way would be linking them manually and ignoring the onComplete but then I loose the main feature of the Subject... Let me explain with an example. Here I only get the result the first time.
    -.kt
    g
    • 2
    • 4
  • m

    Mohamed Ibrahim

    04/16/2019, 7:33 PM
    Hello, I have a case which I need to retrieve data from local first then show it, after that retrieve data from API, then override local data, then show the updated version. I started with concat operator and it doesn't work I think because first time there is no local data to get
    k
    u
    • 3
    • 11
  • n

    nic

    04/18/2019, 7:21 PM
    Hey there, tried searching for this, but wasn't able to pull any results. What's the best way to take an Observable, FlatMapSingle to a Single Observable, but wait until we receive the result of the Single Observable, and decide to either complete or move onto the next one. For example:
    getSomeObservable().flatMapSingle { t -> performAPICallWithData(t) }
    I don't want to
    performAPICallWithData
    until the first one has completed, and I want to use the result from
    performAPICallWithData
    to determine wether I should perform the next one or complete everything
    a
    • 2
    • 7
  • o

    oday

    04/20/2019, 3:33 PM
    unless SingleSource is something that’s not the developer calling the method
    u
    • 2
    • 4
  • u

    ursus

    04/20/2019, 10:11 PM
    ------ Guys, how can I "pass through" emit and also trigger new observable?
    g
    • 2
    • 2
  • u

    ursus

    04/23/2019, 8:31 PM
    @Mohamed Ibrahim what the issue? whole point of retryWhen is that it will resubscribe the source when the function emits anything, and will give up if throwable is emitted
    m
    • 2
    • 2
  • u

    ursus

    04/23/2019, 8:32 PM
    @nic flatmap?
    n
    • 2
    • 5
  • l

    locke

    04/29/2019, 4:39 AM
    Is there a better way to store an observable result for replay than replay subject? I have a stream that I want to create and execute the first time it's called, and then afterwards subscribing to that observable would just return the items that were originally emitted during the first call, rather than redo all of the processing. Describing this sure sounds like describing the lazy pattern (do work once, return repeatedly) but Googling the idea just gives you lazy stream generation, not results.
    g
    a
    +2
    • 5
    • 4
  • m

    Mohamed Ibrahim

    04/30/2019, 11:50 AM
    I have a publish relay which emits items regularly, I just want to get the last tow items each time it emits, the case is to evaluate UI state according to previous and current emissions
    g
    • 2
    • 3
  • a

    alexsullivan114

    04/30/2019, 6:03 PM
    I'm using
    Observable.interval
    to count down from 30 seconds to zero. After that, I want to use
    flatMap
    and continue another Rx chain. I'm not sure what the best way is to actually know when
    after that
    is. Using
    flatMap
    directly after the
    interval
    call obviously doesn't work since the
    flatMap
    gets called after each tick of the interval. RIght now I'm using
    materialize
    and checking if the notification
    isOnComplete
    . Is that the best way to handle this?
    l
    p
    r
    • 4
    • 6
  • u

    ursus

    05/02/2019, 6:05 AM
    Is there a way to force a subclass to subscribe to observable, sort of like abstract methods?
    p
    j
    • 3
    • 5
  • u

    ursus

    05/05/2019, 5:17 PM
    Does anyone know why RxJava fight so much not having subscribers?. I want to just have the action finish regardless of anyone listening; and if they are they get result; else doesnt matter. Sort of like event buses used to do
    d
    • 2
    • 4
  • i

    iex

    05/06/2019, 1:31 AM
    How do I prevent subscribing a subject multiple times to an observable?
    subscribe(subject)
    doesn't return a disposable.
    m
    • 2
    • 2
  • a

    alexsullivan114

    05/06/2019, 5:33 PM
    Ray Wenderlich is having a sale on a few Android books - one of which is is about reactive programming with Kotlin on Android. Check it out if you're interested! https://www.raywenderlich.com/2887766-advanced-spring-fling-sale-ends-this-friday-may-10
    • 1
    • 1
  • a

    Arkadii Ivanov

    05/12/2019, 1:49 PM
    https://badootech.badoo.com/reaktive-a-multiplatform-library-for-reactive-kotlin-android-ios-77b6ff25adb1
    👏 1
    😍 2
    s
    d
    +2
    • 5
    • 11
  • j

    jw

    05/13/2019, 3:14 PM
    Why doesn't this mention Flow which seems like the obvious choice for multiplatform, Kotlin, null-safe Rx?
    d
    a
    +3
    • 6
    • 9
  • u

    ursus

    05/26/2019, 3:51 AM
    How do you guys deal with pagination and database observables? I have refresh() in the domain layer which calls the api, and writes to the database
    fun refresh(page: Int) : Completable {
        .. call api
       database.write(...)
    }
    (edited) and now I want to display progressbar while this is happening + progressbar at the end if page > 1 (edited) the trouble with this is that presentation layer has a query observable opened liek this
    ViewModel {
    
       database.fooQuery()
         .subscribe { ... post to adapter }
    }
    which means that this will emit at the time database.write is called so If map refresh to events of Started, Success, Error Success will come after the database is refreshed which to me is weird, since it should be done in one go, but that means refresh would need to return that data too (edited) tldr; writing to the database is side-effecting - how to deal with that?
    m
    • 2
    • 9
  • m

    Mohamed Ibrahim

    06/02/2019, 3:10 PM
    Could anyone tell us the difference between the Kotlin Flow api and Rxjava, is it a Kotlin implementation for the reactive extension or is it a different thing
    k
    g
    j
    • 4
    • 7
  • j

    jw

    06/04/2019, 12:42 PM
    because the library is built with Java 6 and lacks type_use annotations to denote that the generic is non-nullable
    👍 1
    r
    a
    • 3
    • 3
  • u

    ursus

    06/07/2019, 6:21 AM
    I really believe it should have been different types
    a
    • 2
    • 4
  • u

    ubu

    06/07/2019, 10:31 AM
    Hi there. I'm looking for a way to collect `Observable`'s emissions in bundles of data, some sort of history of the last values. I know it sound like
    buffer()
    operator, but I just can't get it right. When having
    A
    ,
    B
    ,
    C
    ,
    D
    ,
    E
    ,
    F
    emitted one after another with some delay, I would like to have an
    Observable
    emitting:
    [A]
    ,
    [A, B]
    ,
    [A,B,C]
    ,
    [B, C, D]
    ,
    [C, D, E]
    ,
    [D, E, F]
    . We are only interested in last values, so I suppose, we could use here a
    Flowable
    . Thanks.
    g
    a
    • 3
    • 3
  • i

    ivano

    06/13/2019, 7:55 AM
    In java is more syntactic sugarazied than in Kotlin?
    g
    • 2
    • 10
  • u

    ursus

    06/14/2019, 4:43 PM
    there is no switchMap? That like my 1# operator 😕
    k
    • 2
    • 2
  • m

    Mohamed Ibrahim

    06/16/2019, 1:36 PM
    I have a Behavior Relay to control
    MediaPlayer
    (in Activity) from
    viewModel
    , and I have another for settings .. now I want the player relay to only
    skipUntil
    the settings emit an enable sound item. from docs
    skipUntil
    only waits for an Observable to emit at least an item. but what if need to check on that item too, should I use something else or there is something missing
    m
    • 2
    • 3
  • m

    myanmarking

    06/18/2019, 3:07 PM
    observable.create(BatteryLevelObservable()) is the same thing no ?
    g
    • 2
    • 3
  • m

    myanmarking

    06/19/2019, 9:22 AM
    Observable.create<Unit> { System.out.println("Yo") }
    
    class PrintObservable: ObservableOnSubscribe<Unit> {
        override fun subscribe(emitter: ObservableEmitter<Unit>) {
            System.out.println("Yo")
        }
    }
    
    Observable.create(PrintObservable())
    g
    • 2
    • 1
  • a

    alexsullivan114

    06/19/2019, 1:26 PM
    Is the
    BehaviorRelay
    in the
    ViewModel
    or in the fragment/activity?
    m
    • 2
    • 3
  • l

    liminal

    06/21/2019, 4:43 AM
    Trying to justify using RxKotlin on top of RxJava 2. So far I like the plusAssign operator to add to CompositeDisposable as well as clarity of writing out of onNext, onError, etc. anything else that you like? I wonder how RxKotlin will affect RxJava 2 to RxJava 3 conversion
    l
    k
    +2
    • 5
    • 10
  • u

    ursus

    06/21/2019, 3:25 PM
    private fun doPostMessage(...) {
        var messageId: Long? = null
        try {
    		messageId = messageRepository.insertSendingTextMessage(...)
    
            val apiMessage = apiClient.postMessage(...)
    
            messageRepository.updateSentMessageAndParents(apiMessage)
    
        } catch (ex: Exception) {
            if (messageId != null) messageRepository.updateMessageState(messageId, MessageState.ERROR)
            throw ex
        }
    }
    k
    • 2
    • 4
  • u

    ursus

    06/21/2019, 3:26 PM
    but how should I do the catch block where it sees the messageId param?
    k
    • 2
    • 7
Powered by Linen
Title
u

ursus

06/21/2019, 3:26 PM
but how should I do the catch block where it sees the messageId param?
k

kioba

06/21/2019, 3:36 PM
messageRepository
.insertSendingTextMessage(...)
  .flatMap { messageId ->
    apiClient.postMessage(...)
      .flatMap{ apiMessage -> messageRepository.updateSentMessageAndParents(apiMessage) }
      .onErrorResumeNext { error -> 
        messageRepository.updateMessageState(messageId, MessageState.ERROR) }
        .flatMap{ Observable.error(error) }
      }// ONLY if you want to trigger the error but My suggestion would be to return a Succes() / Error() sealed class.
  }
the
.flatMap{ Observable.error(error) }
at the end is there only because when you catch an exception you also throw it again. but it is up to you if you want to keep it or not 🙂
u

ursus

06/21/2019, 3:55 PM
Yea nesting, I thought about that. Thanks. Btw now, how would you add the
if (messageId != null) messageRepository.updateMessageState(messageId, MessageState.ERROR)
catch?
just throw from the
insertSendingTextMessage
, right?
k

kioba

06/21/2019, 3:58 PM
right now if
insertSendingTextMessage
fails, it never executes the inner part so the
onErrorResumeNext { updateMessageState() }
never gets called.
u

ursus

06/21/2019, 3:58 PM
yes, nesting for visiblity gave it to you automatically, nice, thanks
k

kioba

06/21/2019, 3:59 PM
yes exactly as you said, any time 👍
View count: 2