Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debounce/throttle operator that always emits the last value #287

Closed
NachoSoto opened this issue Feb 28, 2017 · 7 comments
Closed

debounce/throttle operator that always emits the last value #287

NachoSoto opened this issue Feb 28, 2017 · 7 comments

Comments

@NachoSoto
Copy link
Member

I just found myself needing such an operator. I have a SignalProducer<[Data], NoError> created with this custom operator:

public func collectIncrementally() -> Signal<[Value], Error> {
    return self
        .map { [$0] }
        .scan([], +)
}

I want to limit how often I get updated arrays, but I do want to make sure that the last value (which will contain all the elements), is always emitted.

@NachoSoto
Copy link
Member Author

Actually I misread the documentation, but I'm still not 100% sure either debounce or throttle will behave this way, so I guess this is a question now, not a feature request :P

@NachoSoto
Copy link
Member Author

NachoSoto commented Feb 28, 2017

Yeah, it does look like if the source signal terminates before the given interval, no more cached values are emitted. This is not documented, and I'm not sure if it's desired behavior. Either way, it would be nice to have an operator that doesn't behave this way.
I looked at Rx's versions and they don't seem to have this either.

@andersio
Copy link
Member

andersio commented Mar 1, 2017

It was documented before the revision. Guess we should put it back, alongside an option. A discardsWhenTerminated parameter with a default of true, perhaps?

5f7109d#diff-09166f905ad1f830ac2dc91f2663c1a5L1728

@NachoSoto
Copy link
Member Author

NachoSoto commented Mar 2, 2017

Guess we should put it back, alongside an option. A discardsWhenTerminated parameter with a default of true, perhaps?

That makes sense to me 👍 Or maybe discardValuesAfterTermination.

@Qata
Copy link
Contributor

Qata commented Feb 5, 2018

@andersio Would it be welcome if I picked up this issue and created an implementation?

@andersio
Copy link
Member

@Qata Sure. 👍

@RuiAAPeres
Copy link
Member

Hello. 👋 Thanks for opening this issue. Due to inactivity, we will soft close the issue. If you feel that it should remain open, please let us know. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants