-
Notifications
You must be signed in to change notification settings - Fork 212
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
Pause Observable #162
Comments
@snowtema Did you look into pausableBuffered ? |
@freak4pc Yes, I used both forms but it also didn't work for my case. func countDownPausableTimer(from: Int, to: Int, quickStart: Bool) -> Observable<Int> {
return Observable<Int>
.timer(quickStart ? 0 : 1, period: 1, scheduler: MainScheduler.instance)
.take(from - to + 1)
.pausableBuffered(self.timerActiveSubject, limit: nil)
// .pausable(self.timerActiveSubject) it also didn't work
.takeWhile { _ in
return !self.forceSkip
}
.map { from - $0 }
}
self.forceSkip = false
self.timerActiveSubject.onNext(true)
self.countDownPausableTimer(from: duration, to: 0, quickStart: true)
.subscribe(onNext: { (sec) in
debugPrint("Timer tick: \(sec)")
self.timesSubject.onNext("\(sec) sec")
}, onCompleted: {
self.timerActiveSubject.onNext(false)
self.buttonEnabledSubject.onNext(true)
})
.disposed(by: self.bag) |
Yup, that's how pausableBuffered works. The problem with an operator like you're suggesting is that it "lies" about when events are emitted. It means that the stream isn't only paused but is also actually delaying additional emitted items further down the stream. I'm not sure how of a popular use case this would be in order to add an operator here, and I feel like we need more community involvement to see if other people would need this enough. What are your thoughts? |
So, what are the most cases for these operators than if it can't pause the initial stream? I agree with you, we need community help. |
@freak4pc I think we should add it a good idea 💡very useful for a jugging and F1 apps 😁 |
@snowtema The issue is that "pausing" just buffers values. What you're asking is that it would buffer the value along with its "time", and then when it emits the buffered elements, it needs to buffer them according to these "time intervals" - which seems rather complicated to me. I wouldn't want to embark on adding such a complex operator in RxSwiftExt unless there's a very wide need/response for it, but that's just my personal opinion :-) |
@freak4pc Well, maybe these operators need to be renamed? :) Because now their names differ with their behaviour and it would mislead. |
@snowtema I don't think so ? The emissions are paused and buffered, and then the buffer is "flushed" after un-paused. I don't think the naming is misleading, you might be adding a different meaning to it which is fine - but not conflicting with the fact the name is correct:) |
Name and description
I have a
timer
Observable and I need to pause it with one condition: when it'll resume it'll continue to emit elements from an element, which be paused with initial delay.Example of use
My code:
The text was updated successfully, but these errors were encountered: