You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current Behavior
When piping multiple finalize actions into an observable, the order of the finalize calls is reversed and does not occur before the completion step. This makes the finalize step untestable because there is no correct place to call the done method in jasmine or jest.
Reproduction
Execute the following test (typescript):
it('does not call finalize in correct order',()=>{of({}).pipe(finalize(()=>console.info('finalize 1')),finalize(()=>console.info('finalize 2'))).pipe(finalize(()=>console.info('finalize 3')),finalize(()=>console.info('finalize 4'))).subscribe(()=>console.info('onNext'),()=>console.info('onError'),()=>console.info('onComplete'));});
If there is a finalize step to be tested, the test will always finish before the finalize code branch was executed. There seems to be no way to prevent this.
Application logic might depend on the correct execution order the finalize steps. Especially if observables are handed through different layers.
Environment
Runtime: Angular v8.0.1, Chrome v75.0.3770.142]
RxJS version: v6.5.2
The text was updated successfully, but these errors were encountered:
Callbacks passed to finalize are called in the order in which unsubscription occurs and that is the order shown in the initial console log. The order is not incorrect. It might not have been what you expected, but it's not incorrect. In any case, the behaviour cannot be changed, as doing so could break existing code.
Application logic might depend on the correct execution order the finalize steps
finalize operator is not an operator designed to provide gauranteed order across multiple subsequent finalize operator chain. It only guarantees 1. called regardless of observable error / completes so some of teardown could be handled in there. 2. called after any complete / error observercallback. Using multiple finalize in a single operator chain is up to consumer, but that's not rxjs guarantees.
Bug Report
Current Behavior
When piping multiple
finalize
actions into anobservable
, the order of thefinalize
calls is reversed and does not occur before thecompletion
step. This makes thefinalize
step untestable because there is no correct place to call thedone
method injasmine
orjest
.Reproduction
Execute the following test (
typescript
):This is the console output:
Expected behavior
Optimally the call order should mirror this console output:
If it is intended, that the
finalize
calls are happening after thecompletion
, this would be the alternative console output:Reasoning
finalize
step to be tested, the test will always finish before thefinalize
code branch was executed. There seems to be no way to prevent this.finalize
steps. Especially if observables are handed through different layers.Environment
The text was updated successfully, but these errors were encountered: