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

    filipradon

    09/19/2019, 8:41 AM
    Hi guys, super quick question. Is there any way to create a cold observable that emits value only once for first subscription made to that observable? It would require an observable with some kind of a memory, or something like that? An observable that passes this test (Observable.just is just a placeholder):
    @Test
       fun `assert observable fires only once ever`() {
           val testObservable = Observable.just(true)
    
           testObservable.test().assertValue(true)
    
           testObservable.test().assertNoValues()
       }
    r
    • 2
    • 1
  • a

    arekolek

    09/19/2019, 11:16 AM
    Something like this?
    val isRead = AtomicBoolean(false)
    val testObservable = Maybe.fromCallable { true.takeUnless { isRead.getAndSet(true) } }.toObservable()
    f
    r
    • 3
    • 5
  • a

    Akram

    09/21/2019, 6:08 PM
    hello guys i just want to know what is the best approach to use rxjava in search when searching some remote server (to prevent fast typing and getting false results )
    p
    u
    • 3
    • 2
  • m

    Mohamed Ibrahim

    09/22/2019, 11:16 AM
    is there any way to handle the nullability of the api response, I tried to use default values in the model, but not sure Retrofit use them in parsing the model to Rx
    p
    • 2
    • 11
  • m

    Maciek

    09/23/2019, 12:21 PM
    Hey guys, question about wiring observables through subjects. My cold finite observable will not come down the downstream unless I'll make subscription with lambda and call manual
    onNext
    on
    subject
    . Can someone explain why `subscribe`method on observable where you pass whole
    subject
    object is not working the same way? Also what is happening with disposable from such
    subscribe
    ? Is it the same disposable when you make subscription on the
    subject
    ?
    Untitled.kt
    a
    • 2
    • 3
  • b

    blakelee

    09/24/2019, 9:02 PM
    Does
    ObservableEmitter.setDisposable(Disposables.fromAction {})
    work the same as
    Observable.doOnDispose{}
    ?
    • 1
    • 1
  • p

    pteale

    09/30/2019, 10:55 AM
    I have a ReplaySubject that is causing an OnErrorNotImplementedException Undeliverable exception reported when calling onComplete() , I can’t seem to track down where this error is occurring though, what can i try for this?
    t
    • 2
    • 2
  • u

    ursus

    10/02/2019, 3:23 AM
    Single.fromCallable {
        someBlockingCode()
    }
    b
    • 2
    • 2
  • s

    Sam

    10/03/2019, 6:48 PM
    Hello everyone, I have some logical want to be done by rx When user click on button download, I will call API to download file by RxKotlin, But if the user click on button multiple time while app’s downloading file, it will not call API until finish download file. So what operate I should use for this logic ? Thanks
    t
    u
    • 3
    • 5
  • m

    Mohamed Ibrahim

    10/08/2019, 12:17 PM
    if
    onComplete()
    or
    onError()
    get called, does the subscription got disposed and cleared from the memory
    u
    • 2
    • 1
  • a

    alexsullivan114

    10/30/2019, 8:27 PM
    I believe you should be able to use
    LiveDataReactiveStreams
    library to bridge the two if that's what you're looking for: https://developer.android.com/reference/androidx/lifecycle/LiveDataReactiveStreams
    👌 1
    👍 2
    a
    • 2
    • 1
  • i

    ivano

    11/05/2019, 12:48 PM
    I am busy in a project where the architect said that we have not to use
    Boolean
    as Flag in the viewModel, but
    Observable<Boolean>
    and so on for everything because he claims that imperative and functional paradigms should not be used togheter. So I am in a situation where if I want to control a simple true false, have to make a
    PublishSubject
    , start it with a value, and then bind it, while I think would be much more efficient to do a simple Boolean
    viewModel.isSomethingTrue
    . Kotlin is not AFAIK a reactive functional language as clojure for instance, so I guess under the hood everytime I use RXJAVA I am going to build a lot on top of an Observable pattern a Boolean anyway! * Is reasonable and more performance effective to combine RXJAVA with ’Imperative” as I think, or I should bind evey single thing and make my Activity classess much more verbose as the architect is saying? *
    a
    • 2
    • 7
  • m

    Mohamed Ibrahim

    11/07/2019, 8:32 AM
    what will happen with this code, does it crash app or pass the exception down to
    onError()
    val testNulls = Observable.create<String> {
            throw NullPointerException()//case 1
    //        it.onNext(null!!) // case 2
            it.onNext("Ahmed")
        }
    a
    u
    • 3
    • 4
  • u

    ursus

    11/11/2019, 5:01 PM
    so I have a list of requests, which I want to upload, however only 5 parallel are allowed, so I have a new scheduler for that, it works, however what the issue is that Observable.fromIterable(it) splits it to per item, but, subscriptions to
    upload
    seem to be race-y, and not in the order of the list
    p
    • 2
    • 3
  • a

    arekolek

    11/14/2019, 8:01 AM
    I didn’t read the whole thread but isn’t
    .flatMap(::someFunction, false, 5)
    what you want?
    u
    • 2
    • 1
  • m

    Mohamed Ibrahim

    11/14/2019, 8:10 AM
    I have splash screen with animation, the animation must be complete then move to the next screen, while doing this I do some api calls and app data setup, I tried to put timeout but other http calls could get earlier .. so animation doesn't complete, I tried to put delay but this will increase the animation time. how to control the stream so if it's passed specific time it will complete the stream.
    m
    • 2
    • 4
  • a

    António Bastião

    11/14/2019, 3:07 PM
    Hi everyone, I’m new with Rx. Can anyone help to understand
    requestData()
    is called twice and how to avoid it?
    Observable.just(Unit)
                    .delay(REPEAT_DELAY, TimeUnit.MILLISECONDS)
                    .repeat()
                    .async(job)
                    .subscribe({ requestData() },
                            {
                                Timber.e(it, "subscribeError")
                            }
                    )
    t
    • 2
    • 5
  • y

    yougin

    11/15/2019, 11:07 AM
    I need to do some clean up just right after all the `Subscriber`s unsubscribe from my
    Observable
    ,
    doOnUnsubscribe
    is invoked upon unsubscribe (dispose) by each of them. Is there a way to wait until everyone unsubscribes?
    b
    • 2
    • 9
  • s

    sanmi

    11/18/2019, 5:19 PM
    I'm trying to test an Rx wrapper I made around firebase Auth create method. I've tried using an argument captor. I just picked up mockito over the weekend. How do I test multiple async call backs with rxjava and mockito?
    k
    a
    • 3
    • 6
  • a

    am414

    11/25/2019, 3:59 AM
    I don't know why this emits immediately not after 30seconds anyone know, What is I am missing here? ??
    Observable<Integer> ob = Observable.timer(30,TimeUnit.SECONDS).just(1);
    
            ob.subscribe(n-> System.out.println(n));
    m
    • 2
    • 1
  • o

    orafaaraujo

    12/02/2019, 8:19 AM
    Hi, everyone Is possible to replace my
    PublishSubject
    to
    Flow
    , or
    BroadcastChannel
    or something more Kotlin-ish way? Thank you
    a
    p
    t
    • 4
    • 8
  • s

    Simon Kågedal Reimer

    12/10/2019, 3:12 PM
    Hi friends! is this a good place for any (beginner level) RxJava questions, or is it more meant for RxKotlin specific things? Anyway, I have a question. I have a
    Flowable
    and I would like to consume all events from it, but add a little delay between each events. How would I best do that?
    k
    a
    • 3
    • 6
  • g

    gregd

    12/11/2019, 7:55 AM
    Hi guys! We have this weird scenario where we have to subscribe to one stream (let’s call it “notification stream”), then - before any item appears - trigger another completable, which immediately returns empty response but - as a side effect - starts emitting on the “notification” stream. And we simply want to return this “notification” stream from our function... Is there a nice RX way of doing this?
    k
    a
    • 3
    • 16
  • b

    blakelee

    12/12/2019, 7:47 PM
    I am trying to test a repeatWhen with a delay but am unable to get any results other than the first one
    @Test fun `test poll`() {
        open class MyClient {
            fun fetchItemFromServer(): Single<Boolean> = Single.just(true)
        }
    
        val testScheduler = TestScheduler()
        val client = mock<MyClient>()
    
        whenever(client.fetchItemFromServer())
                .thenReturn(Single.just(false), Single.just(true))
    
        val test = client.fetchItemFromServer()
                .repeatWhen { it.delay(10, TimeUnit.SECONDS, testScheduler) }
                .distinctUntilChanged()
                .test()
    
        testScheduler.advanceTimeBy(10, TimeUnit.SECONDS)
    
        test.assertResult(false, true)
    }
    d
    • 2
    • 3
  • a

    Ariana

    12/27/2019, 5:31 PM
    Hey all, I’m trying to unit test using Robolectric and am running into a weird scenario Here’s the code block I’m executing:
    Maybe.just(list)
        .flatMapSingle { repository.getStuffList(id) }
        .map { stuffList -> stuffList.filter { stuff -> list.contains(stuff) } }
        .flatMapCompletable { stuffAfterFilter ->
             secondRepository.doThing(stuffAfterFilter)
                  .doOnError { Completable.error(IllegalStateException("failure")) }
                  .andThen { repository.deleteStuff(stuffAfterFilter) }
         }
         .andThen(repository.getStuffList(id))
    What’s the best way to have each call to
    repository.getStuffList(id)
    return different items when they’re called? Right now I’ve got order of operations setup in my test (which has worked in the past), but now the first time the method is called it’s returning
    stuffList2
    instead of
    stuffList1
    whenever(repository.getStuffList("id")).thenReturn(Single.just(stuffList1))
    whenever(secondRepository.doThing(any())).thenReturn(Completable.complete())
    whenever(repository.deleteStuff(any())).thenReturn(Completable.complete())
    whenever(repository.getStuffList("id")).thenReturn(Single.just(stuffList2))
    Am I on the right path here?
    p
    • 2
    • 5
  • j

    Jason

    01/10/2020, 1:51 AM
    Hi all, I am confused how to use Single with Completable properly. I have a get method that returns Single<Data> and a other method just do saving data and return nothing ( Completable ) Code looks like below :
    fun getUserInfo() : Single<UserInfo>
    
    fun save(token: Token) : Completable
    
    fun initialize() {
        getUserInfo()
            .flatMap { 
                // Get token from UserInfo : val token = userInfor.getToken()
                // Call save(token: Token) method to save data
            }
            .subscribeOn(<http://Schedulers.io|Schedulers.io>())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeBy(
                onSuccess = {
                    // HERE:  Using UserInfo to do somtehing
                },
                onError = {
                    Log.d(it)
                }
            )
    }
    How to write code inside
    flatMap
    block ? ( Or is there other operator suitable with this use case?)
    d
    u
    • 3
    • 7
  • o

    ossama

    01/26/2020, 3:53 PM
    Hi all, is it possible to convert a Completable to an Observable? I am calling
    toObservable()
    on my completable, but nothing is emitted in onNext. The doc of the method
    Completable.toObservable()
    says:
    Returns an Observable which when subscribed to subscribes to this Completable and relays the terminal events to the subscriber.
    I am using something like this
    Completable.complete()
        .toObservable<Any>()
        .subscribe { }
    z
    • 2
    • 2
  • i

    iex

    01/28/2020, 6:46 AM
    How do y'all deal with rx java terminating when there are errors? Is there a pattern for observables that shouldn't do this (one of them is probably using
    Result
    as return type)?
    a
    • 2
    • 6
  • i

    iex

    02/03/2020, 9:25 AM
    Is there a point in keeping the
    Disposable
    of a
    Single
    around if you don't plan make it cancellable?
    🇳🇴 1
    u
    a
    • 3
    • 4
  • i

    iex

    02/11/2020, 1:39 PM
    is there something like
    BehaviorSubject
    but where the value is not optional?
    k
    • 2
    • 3
Powered by Linen
Title
i

iex

02/11/2020, 1:39 PM
is there something like
BehaviorSubject
but where the value is not optional?
k

kioba

02/11/2020, 4:02 PM
You mean a default value?
BehaviorSubject.createDefault(1)
i

iex

02/11/2020, 5:40 PM
I mean, that I can call
value
on it and it returns the value, not an optional @kioba
k

kioba

02/11/2020, 6:38 PM
ahh, I don’t know any Subject that a non optional value. Behaviour subject can extended with a property which throws exceptions or returns a default value in case of missing
null
. Altho it works, Wouldn’t suggest the value usage. Sometimes i comes handy but on a longer terms it is a bad decision. Try to subscribe to the stream instead
View count: 3