question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should race have a special case for synchronous observables?

See original GitHub issue

Potential Bug Report

Current Behavior If a race observable is constructed with at least one synchronous observable, the order of events is confusing.

  1. (Optionally) Subscribe to asynchronous observables that come before the first synchronous observable.
  2. Subscribe to the first synchronous observable.
  3. Copy the output from the synchronous observable.
  4. Subscribe and immediately unsubscribe from all other observables.

Step 4 could be ommitted in my opinion. If this is intended behavior, maybe put a note about it in the documentation?

Reproduction https://stackblitz.com/edit/rxjs-ec1mwd

import { race, EMPTY } from 'rxjs';
import { create } from 'rxjs-spy';
import { tag } from 'rxjs-spy/operators';
import { delay, map } from 'rxjs/operators';

create().log(/.*/);
const source = race(
  EMPTY.pipe(delay(100), tag("e0")),
  EMPTY.pipe(tag("e1")),
  EMPTY.pipe(delay(100), tag("e2")),
  EMPTY.pipe(delay(100), tag("e3")),
).pipe(
  tag("output"),
)

source.subscribe();
Tag = output; notification = subscribe; matching /.*/
== Step 1
Tag = e0; notification = subscribe; matching /.*/
== Step 2
Tag = e1; notification = subscribe; matching /.*/
Tag = e1; notification = complete; matching /.*/
== Step 3
Tag = output; notification = complete; matching /.*/
Tag = output; notification = unsubscribe; matching /.*/
Tag = e0; notification = unsubscribe; matching /.*/
Tag = e1; notification = unsubscribe; matching /.*/
== Step 4
Tag = e2; notification = subscribe; matching /.*/
Tag = e2; notification = unsubscribe; matching /.*/
Tag = e3; notification = subscribe; matching /.*/
Tag = e3; notification = unsubscribe; matching /.*/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
mhverbakelcommented, May 24, 2019

Absolutely fine with me. Close it once you created the new one.

0reactions
cartantcommented, May 25, 2019

Closed in favour of #4808

Read more comments on GitHub >

github_iconTop Results From Across the Web

What happens to other observables when rxjs.race() has been ...
race: race() will no longer subscribe to subsequent observables if a provided source synchronously errors or completes.
Read more >
Working with observables in Angular: what we learned at Whoz
Whatever you need to do, going synchronous by subscribing to an observable is never the answer. There is always an operator ready to...
Read more >
Observables Or Promises - DEV Community ‍ ‍
Observables were introduced to JavaScript due to the lack of native support for multiple streams of asynchronous data/event in JavaScript.
Read more >
Chapter 1. Reactive Programming with RxJava - O'Reilly
Generally, an Observable is going to be asynchronous, but it doesn't need to be. An Observable can be synchronous, and in fact defaults...
Read more >
Callbacks vs Promises vs RxJS vs async/await - Academind
The same would be the case for functions where you reach out to a web ... you may have a look at Promise.all()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found