WICG / observable

Observable API proposal
https://wicg.github.io/observable/
Other
543 stars 12 forks source link

Fix Observable unsubscription timing #120

Closed domfarolino closed 4 months ago

domfarolino commented 4 months ago

This PR "fixes" Observable unsubscription/teardown timing. As a matter of accidental historical precedent, Observables in JavaScript (but not in other languages) had implemented the "rule" that upon Subscriber#error() or Subscriber#complete(), the subscriber would:

  1. First, invoke the appropriate Observer callback, if provided (i.e., complete() or error() callback).
  2. Signal abort Subscriber#signal, which invokes any teardowns and also fires the abort event at the signal.

However, after dom@chromium.org discussed this more with ben@benlesh.com, we came to the conclusion that the principle of "as soon as you know you will teardown, you MUST close the subscription and any upstream subscriptions" should be followed. This means the above steps must be inverted. This is a small-in-size but medium-in-impact design change for the Observable concept, and led to a blog post and an announcement that the RxJS library intends to change its historical ordering of these events.

This PR is made alongside https://crrev.com/c/5311097 and https://github.com/web-platform-tests/wpt/pull/44682, which fixes the Chromium implementation and test expectations respectively.


Preview | Diff