Add close state to finally operator?
See original GitHub issue@matthewwithanm presented a scenerio here that I think we can address with a non-breaking change to the finally operator.
That is that we could provide, as an argument to finally
’s callback, a flag of some sort to declare whether or not it was finalized because of error
, complete
or unsubscribe
.
Strawman:
source$.finally((type: string) => {
switch(type) {
case 'complete':
doThing1();
break;
case 'error':
doThing2();
break;
case 'unsubscribe':
doThing3();
break;
}
})
The only additional thing I can think of is additionally providing the error in the event of an error, but I’m not sure how helpful that would be.
Thoughts?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Observable Finally on Subscribe - Stack Overflow
The older and now deprecated "patch" operator was called finally() (until RxJS 5.5). I think finalize() operator is actually correct.
Read more >RxJS finalize operator to execute logic on Observable ...
An RxJS operator for executing logic when the Observable terminates.
Read more >RxJs SwitchMap Operator: How Does It Work?
In the end, we will be covering a very common use case of the operator (emitting values that combine the output of multiple...
Read more >RxJS: Observables, Observers and Operators Introduction
When an Observable produces values, it then informs the observer, calling .next() when a new value was successfully captured and .error() ...
Read more >What Does The Finalize Operator Do In Angular/RxJS
I've recently gotten into the habit of using the finalize operator when using RxJS in Angular. For the most part, if you've used...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@martinsik We wound up with basically the same thing. I think you need to wrap your operator body in a
defer()
though. Otherwise you’re using the samecompleted
anderrored
variables for every subscription and once one errors they all will.@matthewwithanm You’re right, it should be wrapped inside
defer
.