kefirjs/kefir

takeErrors(1) does not end stream immediately?!

ivan-kleshnin opened this issue · 3 comments

I have the following code for SSR:

sinks.state$
    .skip(1)                                     // skip initial state
    .merge(K.later(500, sinks.state$).flatMap()) // timeout 500ms
    .take(1)                                     // a state to render
    .takeErrors(1)
    .observe(state => {
      console.log("???")
      let appHTML = ReactDOMServer.renderToString(<sinks.Component/>)
      res.send(layout({appHTML, state}))
    }, error => {
      console.log("!!!", error.message)
      res.status(500).send("500")
    })

What I have noticed is that takeErrors(1) does not end stream after the first error immediately.
At least one value event passes through after that:

Listening on port 8080
!!! Request failed with status code 500
??? -- why this event coming @_@

Is this an intended behavior or a bug? RxJS ends on error automatically and I think in Kefir it would be good to end streams on takeErrors(1) immediately as well. Otherwise, for the above case, it will be necessary to mess with global variables.

It should end immediately. There is a test covering this case, which appears correct, not sure why that's not working as expected for you. I did make some changes to take and takeErrors somewhat recently. Do you have a public reproducible example we can take a look at?

I'll try to prepare one tomorrow.

I take my words back – it works as expected (ends immediately).
Sorry for misinformation, something else was in effect here – not a Kefir's problem.