Replies: 1 comment
-
I personally wouldn't go for the second one because (even though I know rxjs isn't made for angular) I rarely subscribe to my observable directly. Thus it would be almost useless for me! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
I frequently find code where users need to add a
finalize()
operator just to execute some finalization related code, when they don't even have any other operators to deal with. This adds complexity and boilerplate to something that should be simple.Possible Solutions
Proposal 1: Add a
finalize: () => void
handler to thesubscribe
call.This would mean that the following would work:
It should always fire after all teardown as occurred (and therefor after any
complete
orerror
calls). If we ever did add anunsubscribe
handler (I'm against this), it would fire after that as well.Gotcha: We CANNOT add this to
Observer<T>
Subscriber
andSubject
implementObserver<T>
as a means of sending notifications to a consumer. There's no reason to "forward" a "finalize" notification to a consumer. Finalize is an event that happens as a result ofcomplete
,error
, orunsubscribe
.For prior art we have
tap({ finalize: () => {} })
and of coursefinalize(() => {})
.Proposal 2: Add a
finally()
method toSubscription
For this, we'd add a new method to
subscription
that worked a lot likePromise#finally
. Basically, adding a way to add a finalization callback in a familiar way.Con: This is basically
add
only it returns theSubscription
This really means we'd be adding two different ways to add a finalizer to a subscription. And
add
has been working fine. But then we're also in the same boat as promises where you can't "unfinally" your handler (nor can you "unthen" a standard promise). This makes for a duplicate, if a little deficient API for finalization.Plus there are questions: Does it return the same Subscription instance? A new one? etc.
Proposal 3: Do nothing
Just what it sounds like. The
finalize()
operator has been working, even if it's a little cumbersome some times. Nothing new to worry about.Beta Was this translation helpful? Give feedback.
All reactions