In rxjs, given any Observable
we can do observable.pipe(finalize(() => some_cleanup())
to run some_cleanup
in any case (error or completion).
I was wondering if there is the errrr…. opposite of it, like an initialize()
to run some setup code upon subscription.
Like this:
new_observable = observable.pipe(
initialize(() => setup_things()),
finalize(() => some_cleanup()),
)
Later we can subscribe to new_observable
conveniently without even wondering if we need to setup something beforehand.