Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v7.0-beta.7] firstValueFrom does not unsubscribe synchronously #5811

Closed
spalger opened this issue Oct 8, 2020 · 0 comments
Closed

[v7.0-beta.7] firstValueFrom does not unsubscribe synchronously #5811

spalger opened this issue Oct 8, 2020 · 0 comments
Labels
bug Confirmed bug

Comments

@spalger
Copy link

spalger commented Oct 8, 2020

Bug Report

Probably working as intended, I'm just looking for clarification

Current Behavior
When firstValueFrom() subscribes to an observable it behaves subtly different than source.pipe(first()).toPromise() because it doesn't unsubscribe from source until after it is done synchronously emitting events.

Reproduction

import { Observable, firstValueFrom } from 'rxjs'; 

const values = [1,2,3]
const source = new Observable(subscriber => {
  while (!subscriber.closed && values.length) {
    subscriber.next(values.shift()!)
  }
  
  subscriber.complete();
});

firstValueFrom(source).then(console.log);
console.log(values) // expect values = [2, 3]

Expected behavior
I expect that subscriber.closed would be true because the consumer is only expecting a single value.

Environment

  • RxJS version: 7.0.0-beta.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants