daniellansun commented on PR #2987:
URL: https://github.com/apache/groovy/pull/2987#issuecomment-6250654658
Here is the JavaScript solution:
```JS
let n = 0;
const stream = new ReadableStream({
pull(controller) {
n += 1;
if (n === 3) {
controller.error(new Error('sensor failed')); // close with the cause
return;
}
controller.enqueue(n * n);
}
});
const seen = [];
try {
for await (const value of stream) {
seen.push(value);
}
} catch (failure) {
console.log(failure.message); // sensor failed
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]