Is there a built in equivalent of `Observable.neve...
# coroutines
p
Is there a built in equivalent of
Observable.never()
?
l
Yes,
emptyFlow<Nothing>()
or
flow { awaitCancellation() }
depending on your use case.
p
So there is nothing built in; emptyFlow is rather Observable.empty
l
There are a bunch of operators that RxJava has that are replaced with
onStart
in Flow as well, and it's intentional (see Roman Elizarov talk at KotlinConf 2019)
p
Yeah, emptyFlow should have been replaced with
flow {]
as well 😛
l
How would you name a function that does
flow { awaitCancellation() }
? 😝
And how often do you need it?
Personally… never
p
nothingEmittingForeverHangingFlow()
l
That's mouthful
p
But funny
l
Feel free to have it in your codebase 😄
m
I called it "infiniteEmptyFlow" in my projects 😄
e
MutableSharedFlow<Nothing>.asSharedFlow()
also never emits or terminates
u
Can I ask the use case for
never
? I use
empty
all the time though.
b
never
is useful in unit tests, when some observable should be initialized, but you don't care about it
p
Yep. Especially when you have stuff like
first()
in the processing line
161 Views