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

Fill with Next(value) event with interval. #123

Open
minuscorp opened this issue May 26, 2016 · 10 comments
Open

Fill with Next(value) event with interval. #123

minuscorp opened this issue May 26, 2016 · 10 comments

Comments

@minuscorp
Copy link

I use MutableProperty to fill values coming through a Bluetooth protocol, and them being represented at real-time in different sections of the application.

I was thinking (and maybe it could be useful to add in this library) a method which fills a producer or signal with .Next(value) events eachtime the original producer or signal doesn't send any value for a NSTimeInterval. Using the DateSchedulerType shouldn't be hard to achieve this behavior.
When the signal or the producer sends again a value, the "Default" event is replaced inmediately and the countdown starts again.

What do you think?

@RuiAAPeres
Copy link
Member

I was thinking (and maybe it could be useful to add in this library) a method which fills a producer or signal with .Next(value) events eachtime the original producer or signal doesn't send any value for a NSTimeInterval

How can it fill it, if there is no value being sent?

Could you put an example of the behaviour you would expect from this operator?

@minuscorp
Copy link
Author

I was thinking something like this:

// Let's suppose valueProperty is MutableProperty<String?>
SomeUnstableService.valueProperty.producer.fillWithNext(.Next("N/A"), timeInterval: 5.0, scheduler: QueueScheduler.mainQueueScheduler).startWithNext {
    stringValue in
    print(stringValue)
}

While the service is setting the .value of valueProperty each time the correct data is being sent through the service:

func onDataReceived(value: String){
    self.valueProperty.value = value
}

But when more than timeInterval time has passed I want in that concrete producer observer to receive the "N/A" string every timeInterval has passed while the self.valueProperty.value = value hasn't been set again.

@RuiAAPeres
Copy link
Member

RuiAAPeres commented May 26, 2016

I think you would be able to achieve that with a debounce + merge.

@minuscorp
Copy link
Author

Could you give me a hint on this? I've tried but I cannot accomplish the behavior 😞

@RuiAAPeres RuiAAPeres changed the title [ENHANCEMENT] Fill with Next(value) event with interval. Fill with Next(value) event with interval. May 26, 2016
@RuiAAPeres
Copy link
Member

Thought a bit more about this and I don't think it's possible, so disregard my initial comment. Regarding the new operator:

  1. Why instead of an event, you just send the Value. (e.g: SomeUnstableService.valueProperty.producer.fillWithNext("N/A", timeInterval: 5.0, scheduler: QueueScheduler.mainQueueScheduler))
  2. The naming, doesn't really convey what's its purpose.

@minuscorp
Copy link
Author

1.- That's the way, as it should be type V in the argument. I confused the description.
2.- Maybe we can think of a name such as... .refillWith(value: V, timeInterval: NSTimeInterval, scheduler: DateSchedulerType) or timeoutWith(...) , replenishWith(...)

@neilpa
Copy link
Member

neilpa commented May 26, 2016

Thinking abstractly, this sounds like a "decay" model that you're trying to respond to. In those terms, creating a decay operator, and then mapping on that result might be the way to go. I'd like to think a bit more on it though.

@minuscorp
Copy link
Author

The summary of this operator is that given a stream of values at least Value is recieved each timeInterval if no other .Next event has been sent.

@neilpa
Copy link
Member

neilpa commented May 27, 2016

I understand that. My point about decay is it may be a more general concept hiding under the operator that you're asking for.

@minuscorp
Copy link
Author

I have no counter arguments with that operator naming!

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

3 participants