RxJS: Stopped Notifications

Nicholas Jamieson
3 min readDec 7, 2020
Photo by Erwan Hesry on Unsplash

RxJS — and Rx in general — offers a bunch of guarantees that make it possible to compose observable chains. Specifically, it’s guaranteed that:

  • observers won’t receive notifications after an error or complete notification; and
  • observers won’t receive notifications after explicitly unsubscribing.

There is more information about this in the Observable Contract.

The guarantees allow for the declarative composition of observable chains: developers can focus on composing behaviours rather than keeping track of state. Without the guarantees, developers would be checking for errored or completed sources and composition would be more difficult.

A quirk that stems from these guarantees is that it’s possible for an error channel to be closed. For example, if an error occurs when an observable is being torn down, it’s not possible for that error to be reported to the observer — the observer will have already received a complete or error notification or will have already been explicitly unsubscribed. In RxJS, observers in this state are referred to (internally) as stopped.

Over the last few RxJS versions, the way this situation has been dealt with has changed.

Version 5

--

--

Nicholas Jamieson

RxJS core team member; front-end developer; mentor; speaker; open-source contributor