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
When a race is won by a source observable that completes or errors synchronously, the implementation continues to subscribe to subsequent source observables.
This does not happen if the source observable that wins the race does so by emitting a value notification.
Reproduction
This code:
import{defer,EMPTY,of,race,throwError}from"rxjs";import{delay}from"rxjs/operators";race(defer(()=>{console.log("subscribed to 1");returnof(1).pipe(delay(100));}),defer(()=>{console.log("subscribed to EMPTY");returnEMPTY;}),defer(()=>{console.log("subscribed to 3");returnof(3).pipe(delay(300));})).subscribe({complete: ()=>console.log("won"),error: ()=>console.log("won with error")});
will output:
subscribed to 1
subscribed to EMPTY
won
subscribed to 3
and this code:
race(defer(()=>{console.log("subscribed to 1");returnof(1).pipe(delay(100));}),defer(()=>{console.log("subscribed to error");returnthrowError(newError("kaboom"));}),defer(()=>{console.log("subscribed to 3");returnof(3).pipe(delay(300));})).subscribe({complete: ()=>console.log("won"),error: ()=>console.log("won with error")});
will output:
subscribed to 1
subscribed to error
won with error
subscribed to 3
Expected behavior
For races won via completion or error, the behaviour should be like this code and subscriptions to subsequent source observables should not be made:
race(defer(()=>{console.log("subscribed to 1");returnof(1).pipe(delay(100));}),defer(()=>{console.log("subscribed to 2");returnof(2);}),defer(()=>{console.log("subscribed to 3");returnof(3).pipe(delay(300));})).subscribe({complete: ()=>console.log("won"),error: ()=>console.log("won with error")});
will output:
subscribed to 1
subscribed to 2
won
Environment
Runtime: Node
RxJS version: 6.5.2
The text was updated successfully, but these errors were encountered:
Bug Report
This is a re-write of the bug found in #4806.
Current Behavior
When a
race
is won by a source observable that completes or errors synchronously, the implementation continues to subscribe to subsequent source observables.This does not happen if the source observable that wins the race does so by emitting a value notification.
Reproduction
This code:
will output:
and this code:
will output:
Expected behavior
For races won via completion or error, the behaviour should be like this code and subscriptions to subsequent source observables should not be made:
will output:
Environment
The text was updated successfully, but these errors were encountered: