Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 7
    "In the ES7 spec, which RxJS 5.0 follows (but RxJS 4.0 does not), the two are NOT the same." It's very important to notice that specifications change over time. Which is very annoying, so something that it's correct now, maybe it wasn't in the past or won't be in the future. So the correct answer has always to specify for which version of what (and this one does). Commented Feb 1, 2017 at 10:22
  • With forEach do we need to unsubscribe or does it handles by itself? Commented Jan 13, 2019 at 8:08
  • 3
    @SamiullahKhan : Your question requires more complexity than yes/no to answer. forEach subscribes internally, and then returns a promise; with that promise you have no way to unsubscribe. However, you also have no way to cancel, so you probably assume it will complete or fail without your intervention. The conventional design expectation of observable libraries is that Unsubscribe happens automatically upon either Complete or Error. Therefore, if forEach conceptually works for you, then no, you don't need to unsubscribe. forEach does not Unsubscribe but Complete and Error do. Commented Jan 13, 2019 at 17:10
  • So, as I understand, forEach is useful for something like await obs.forEach(doSomething), where your method will finish after the observable completes. On the other hand, when the lifetime of the observer may be shorter than the one of the observable, you'll use .subscribe() with the corresponding .unsubscribe(). Commented Jan 20, 2021 at 19:00