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

test: add test for from(asynciterable) unsubscribe #6491

Merged
merged 1 commit into from Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 29 additions & 1 deletion spec/observables/from-spec.ts
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { TestScheduler } from 'rxjs/testing';
import { asyncScheduler, of, from, Observer, observable, Subject, noop } from 'rxjs';
import { asyncScheduler, of, from, Observer, observable, Subject, noop, Subscription } from 'rxjs';
import { first, concatMap, delay, take, tap } from 'rxjs/operators';
import { ReadableStream } from 'web-streams-polyfill';

Expand Down Expand Up @@ -109,6 +109,34 @@ describe('from', () => {
});
});

it('should finalize an AsyncGenerator on unsubscribe', (done) => {
const results: any[] = [];
const sideEffects: any[] = [];
let subscription: Subscription;

async function* gen() {
try {
let i = 0;
while (true) {
sideEffects.push(i);
yield await i++;
if (i === 2) {
subscription.unsubscribe();
}
}
} finally {
results.push('finalized generator');
expect(sideEffects).to.deep.equal([0, 1, 2]);
expect(results).to.deep.equal([0, 1, 'finalized generator']);
done();
}
}

const source = from(gen());

subscription = source.subscribe(value => results.push(value));
});


it('should finalize a generator', () => {
const results: any[] = [];
Expand Down