question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emit immediately by default

See original GitHub issue

I don’t agree with the current false default value for emitImmediately. I would argue most idiomatic reactive code using FlowBinding will want the initial value. In addition, RxBinding emits the initial value by default, and FlowBinding clearly advertises itself as its direct counterpart.

Obviously this is a behavior breaking change, but an important one to get right early.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
svenjacobscommented, Jun 5, 2020

What about making emitImmediately = true the default and remove that parameter and distinguish between an initial-value flow with InitialValueFlow and a non initial-value flow with Flow as usual.

Implementation of InitialValueFlow could look like this

class InitialValueFlow<T>(private val flow: Flow<T>) : Flow<T> by flow {

    fun skipInitialValue(): Flow<T> = flow.drop(1)
}

or as an inline class

inline class InitialValueFlow<T>(private val flow: Flow<T>) : Flow<T> {

    fun skipInitialValue(): Flow<T> = flow.drop(1)

    @InternalCoroutinesApi
    override suspend fun collect(collector: FlowCollector<T>) = flow.collect(collector)
}

I still think representing that different behaviour through the type system is better than having a boolean parameter.

4reactions
chris-hornercommented, Jun 5, 2020

Having the flow emit immediately by default feels more natural to me too.

Thinking on it a bit, I agree that @svenjacobs’s approach is probably the best bet. I always appreciated the explicit skipInitialValue() in RxBinding, and providing this behaviour through a type rather than a parameter reads a little nicer.

Thumbs up from me 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

RXJS emit immediately and retry - Stack Overflow
We would like to emit the incomplete data from the first http response and continue making http requests until processed is true.
Read more >
defaultIfEmpty - Learn RxJS
Emit given value if nothing is emitted before completion. ... Example 1: Default for empty value ... Example 2: Default for Observable.empty.
Read more >
A Guide to Vue $emit - How to Emit Custom Events in Vue
Using emit , we can trigger events and pass data up the component ... <script> export default { methods: { handleChange (event) {...
Read more >
interval - RxJS
The first emission is not sent immediately, but only after the first period has passed. By default, this operator uses the async SchedulerLike...
Read more >
First operator - ReactiveX
The latest operator is similar, but rather than blocking to wait for the next emitted item, it immediately returns the most-recently-emitted item, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found