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

Missing `takeUntil` on `Observable` #162

Closed
ziggystar opened this Issue Jun 15, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@ziggystar
Copy link

ziggystar commented Jun 15, 2016

I want to end an Observable once another Observable switches. I think this could be achieved with a method takeUntil(other: Observable[_]) analogously to dropUntil.

@alexandru

This comment has been minimized.

Copy link
Member

alexandru commented Jun 15, 2016

@ziggystar OK, will happen, not sure when. If you'd like to give it a shot, you can also send a PR :-P

In the meantime you could play with switchMap:

val trigger = myTriggerObservable.headF.completed

Observable.fromIterable(Seq(source, trigger)).switchMap(identity)

This operator works like merge, but when a new observable is emitted, it cancels the previous one.
It's not ideal though. This is like a hammer you can apply in place of a screwdriver.

@alexandru

This comment has been minimized.

Copy link
Member

alexandru commented Jun 15, 2016

@ziggystar the alternative I outlined above doesn't work. Sorry, I'm tired. I mean, my description of switch is correct, but it doesn't do what you want.

OK, here's another approach:

val trigger = Observable.now(true) ++ myTriggerObservable.headF.completed ++ Observable.now(false)
Observable.combineLatest2(source, trigger)
  .takeWhile(_._2).map(_._1)

@alexandru alexandru closed this in d0fb8ff Jun 29, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.