`abortableAsyncIterable()` should call `.return()` on the generator once aborted
Describe the bug
Async generators canceled by abortableAsyncIterable don't have their return method called, so they don't get the opportunity to clean up resources.
https://github.com/denoland/deno_std/blob/d84f4b1c947b6b09df5e9a2e50e8f1549fe615fd/async/abortable.ts#L135-L139
Expected behavior
An example of a library which handles this is abortable-iterator:
https://github.com/alanshaw/abortable-iterator/blob/68c554cb40bd160216abb7200b54015aad0bd9a8/src/index.ts#L103-L106
Environment
- std version: 1.36.0
Contributions are welcome 🙂
const stream = source
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream({ allowCR: true }))
try {
for await (const message of abortable(stream, signal)) {
this.dispatch({ message });
}
} catch (e) {
console.error(e)
}
this results with:
error: Leaks detected:
- A text decoder was created during the test, but not finished during the test. Close the text decoder by calling `textDecoder.decode('')` or `await textDecoderStream.readable.cancel()`.
and when trying to stream.cancel() in catch I get this:
TypeError: Cannot cancel a locked ReadableStream.
@iuioiua Interestingly this works when stream is created by fetch for example but I'm having strange errors when using streams created in code but this is a problem with deno itself I think. Reported it here: https://github.com/denoland/deno/issues/19946#issuecomment-2254489046