Skip to content

Add .throw and .return interface methods to StreamToAsyncIterator #1

@basicdays

Description

@basicdays

Generators can also provide methods to implement a return and throw feature to help handle additional syntax operators in a for-of loop.

For example:

const readStream = fs.createReadStream(__filename);
    for await (const chunk of new S2A(readStream)) {
        console.log(chunk);
        if (chunk === ...) break;
    }

This is how it is used within a vanilla generator:

function* gen(){
  try {
    for (var i = 0;; i++) yield i;
  } finally {
    console.log('done');
  }
}

for (var i of gen()) {
  if (i > 5) break;
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions