···
+
describe('toAsyncIterable', () => {
+
it('creates an async iterable mirroring the Wonka source', async () => {
+
let sink: Sink<any> | null = null;
+
const source: Source<any> = _sink => {
+
if (signal === TalkbackKind.Pull) pulls++;
+
const asyncIterator = sinks.toAsyncIterable(source)[Symbol.asyncIterator]();
+
expect(await asyncIterator.next()).toEqual({ value: 0, done: false });
+
expect(await asyncIterator.next()).toEqual({ value: 1, done: false });
+
expect(await asyncIterator.next()).toEqual({ done: true });
+
it('buffers actively pushed values', async () => {
+
let sink: Sink<any> | null = null;
+
const source: Source<any> = _sink => {
+
if (signal === TalkbackKind.Pull) pulls++;
+
const asyncIterator = sinks.toAsyncIterable(source)[Symbol.asyncIterator]();
+
expect(await asyncIterator.next()).toEqual({ value: 0, done: false });
+
expect(await asyncIterator.next()).toEqual({ value: 1, done: false });
+
expect(await asyncIterator.next()).toEqual({ done: true });
+
it('asynchronously waits for pulled values', async () => {
+
let sink: Sink<any> | null = null;
+
const source: Source<any> = _sink => {
+
if (signal === TalkbackKind.Pull) pulls++;
+
const asyncIterator = sinks.toAsyncIterable(source)[Symbol.asyncIterator]();
+
const promise = asyncIterator.next().then(value => {
+
await Promise.resolve();
+
expect(resolved).toBe(false);
+
expect(await promise).toEqual({ value: 0, done: false });
+
expect(await asyncIterator.next()).toEqual({ done: true });
+
it('supports cancellation via return', async () => {
+
let sink: Sink<any> | null = null;
+
const source: Source<any> = _sink => {
+
if (signal === TalkbackKind.Close) ended = true;
+
const asyncIterator = sinks.toAsyncIterable(source)[Symbol.asyncIterator]();
+
expect(await asyncIterator.next()).toEqual({ value: 0, done: false });
+
expect(await asyncIterator.return!()).toEqual({ done: true });
+
expect(await asyncIterator.next()).toEqual({ done: true });
+
expect(ended).toBeTruthy();
+
it('supports for-await-of', async () => {
+
const source: Source<any> = sink => {
+
if (signal === TalkbackKind.Pull) {
+
sink(pulls < 3 ? push(pulls++) : SignalKind.End);
+
const iterable = sinks.toAsyncIterable(source);
+
const values: any[] = [];
+
for await (const value of iterable) {
+
expect(values).toEqual([0, 1, 2]);
+
it('supports for-await-of with early break', async () => {
+
const source: Source<any> = sink => {
+
if (signal === TalkbackKind.Pull) {
+
sink(pulls < 3 ? push(pulls++) : SignalKind.End);
+
const iterable = sinks.toAsyncIterable(source);
+
for await (const value of iterable) {
+
expect(closed).toBe(true);
describe('toObservable', () => {
it('creates an Observable mirroring the Wonka source', () => {