0

I have the following code:

const kickstart$ = curry((pred, iStream, hStream) =>
    iStream()
    .pipe(
        take(1),
        flatMap(({processId: pid}) => poller$(hStream(pid))),
        takeWhile(pred),
        catchError(x => of(x))
    )
)

The takeWhile statement is there to stop the stream once the pred function returns false. The problem is, I also want those final values to be emitted so that the subscriber can know what the final state of the stream was, which contains information like status: stopped or status: error, but then I want it to end after that.

If I only check for status !== "stopped" || status !== "error" in my takeWhile, then that final event will not get emitted.

How do I also include that final event?

markovchain
  • 515
  • 1
  • 10
  • 25

1 Answers1

2

Which rxjs version do you use?

There already is a takeWhile overload with a boolean flag for inclusive last.

takeWhile(pred, true)

If you're using older versions you will have to do something else like concating the last emited value after takeWhile

I believe inclusive last was added in 6.4.0.

Roberto Zvjerković
  • 9,657
  • 4
  • 26
  • 47
  • Thanks for the info. I'm using 6.5.1, so this works for me. Strangely, I did not see this documented in [here](https://www.learnrxjs.io/operators/filtering/takewhile.html) or [here](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-takeWhile). Thanks for the help! – markovchain Apr 25 '19 at 12:57
  • 1
    I know, I just posted a merge request for https://www.learnrxjs.io/operators/filtering/takewhile.html :) – Roberto Zvjerković Apr 25 '19 at 13:12
  • 1
    Oh, there it is already! – Roberto Zvjerković Apr 25 '19 at 13:12