Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

flatMap should close both iterators when return/throw are called, not just the outer one #163

@bakkot

Description

@bakkot

Consider:

function* words() {
  try {
    yield 'abc';
    yield 'xyz';
  } finally {
    console.log('underlying iterator closed');
  }
}

let chars = words().flatMap(function* (arg) {
  try {
    yield* arg.split('');
  } finally {
    console.log('mapping iterator closed');
  }
});

for (let c of chars) {
  break;
}

I would expect this to print 'mapping iterator closed' as well as 'underlying iterator closed'. But it doesn't; only the underlying one gets closed.

This is related to #114, but more so: even the JS which that issue says is roughly equivalent to the current implementation would close the mapping iterator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions