We learned how to implement a very basic core in the last section. Earlier in the chapter, however, it was mentioned that sometimes your Observable will allocate resources or will display a behavior where it clearly won't be able to stop generating values. It is our responsibility to handle such situations in a graceful manner. RxJS has clearly laid out a path here, which is to define a cleanup function and ensure it is invoked upon calling unsubscribe(). Let's show such a scenario, where we clearly need to care about cleaning up:
// rxjs-core/Observer-with-subscription.tsinterface Subscription { unsubscribe();}class MyObservableWithSubscription { static create(behaviourFn): MyObservableWithSubscription { return new ...