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

nested concatMaps no longer next values to destination in 6.3.0 #4071

Closed
benlesh opened this issue Aug 30, 2018 · 4 comments · Fixed by severest/retrobot#221
Closed

nested concatMaps no longer next values to destination in 6.3.0 #4071

benlesh opened this issue Aug 30, 2018 · 4 comments · Fixed by severest/retrobot#221
Assignees
Labels
bug Confirmed bug

Comments

@benlesh
Copy link
Member

benlesh commented Aug 30, 2018

Bug Report

Current Behavior
Currently if you nest a concatMap inside of a concatMap, and the source completes, the inner most concatMap will not forward along values.

Reproduction

import { timer, from } from 'rxjs';
import { concatMap, tap } from 'rxjs/operators';

function wait(ms){
  return new Promise(res => {
    setTimeout(() => res('poop'), ms);
  })
}

timer(10).pipe(
  concatMap(() => from(wait(20)).pipe(
    concatMap(() => {
      console.log('here');
      return from(wait(20)).pipe(
        tap(x => console.log('>', x))
      );
    })
  ))
)
.subscribe(x => console.log('>', x));

Expected behavior
It should work like it did in 6.2

Environment

  • Runtime: all
  • RxJS version: 6.3.0

Possible Solution

None

@benlesh benlesh self-assigned this Aug 30, 2018
@benlesh
Copy link
Member Author

benlesh commented Aug 30, 2018

cc @hansl @IgorMinar

@benlesh
Copy link
Member Author

benlesh commented Aug 30, 2018

This seems to specifically have to do with promises, FYI:

    const results: any[] = [];

    of(1).pipe(
      concatMap(() =>
        from(Promise.resolve(2)).pipe(
          concatMap(() => Promise.resolve(3))
        )
      )
    )
    .subscribe({
      next(value) { results.push(value); },
      complete() { results.push('done'); }
    });

    setTimeout(() => {
      expect(results).to.deep.equal([3, 'done']);
      done();
    }, 0);

@cartant
Copy link
Collaborator

cartant commented Aug 30, 2018

Specifically, it seems to be due to the outermost promise.

If you comment out the from, replacing it with of(2, asapScheduler), it works fine:

of(1).pipe(
  concatMap(() =>
    from(Promise.resolve(2))
    // of(2, asapScheduler)
    .pipe(
      concatMap(() => defer(() => {
        console.log('sub');
        return of(3, asapScheduler).pipe(
          tap(() => console.log('next')),
          finalize(() => console.log('unsub'))
        );
      }))
    )
  )
)
.subscribe({
  next(value: any) { results.push(value); },
  complete() { results.push('done'); }
});

When the promise is used, it appears to subscribe to the innermost observable and then immediately unsubscribe. And then it seemingly doesn't complete, as there's no done in results.

I can look further into this later, if you've not already resolved the regression in the interim.

@cartant
Copy link
Collaborator

cartant commented Aug 31, 2018

This fails, too, and does not use a promise:

of(1).pipe(
  concatMap(() =>
    defer(() => {
      console.log('outer-sub');
      return of(2, asapScheduler).pipe(
        tap(() => console.log('outer-next')),
        finalize(() => console.log('outer-unsub'))
      );
    })
    .pipe(
      concatMap(() => defer(() => {
        console.log('inner-sub');
        return of(3, asapScheduler).pipe(
          tap(() => console.log('inner-next')),
          finalize(() => console.log('inner-unsub'))
        );
      }))
    )
  )
)
.subscribe({
  next(value: any) { results.push(value); },
  complete() { results.push('done'); }
});

setTimeout(() => {
  console.log(results);
}, 0);

It emits a value, but does not complete. Works under 6.2.2.

cartant added a commit to cartant/rxjs that referenced this issue Aug 31, 2018
cartant added a commit to cartant/rxjs that referenced this issue Aug 31, 2018
Don't add self as parent.
Closes ReactiveX#4071
@lock lock bot locked as resolved and limited conversation to collaborators Sep 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants