Skip to content

[Blazor WebAssembly] Support for Cancelling HTTP Requests by Diposing Response Stream #64225

@tpeczek

Description

@tpeczek

When working with ReadableStream in JavaScript, one can call ReadableStreamDefaultReader.cancel() which will triger request cancellation if the server is still streaming.

In Blazor WebAssembly this is currently not possible, as WasmHttpReadStream uses the reader only to advance the ReadableStream and on dispose only diposes the references to JavaScript objects. It looks like this functionality could be achieved by adding call to cancel() in WasmHttpReadStream.Dispose.

private sealed class WasmHttpReadStream : Stream
{
    ...

    protected override void Dispose(bool disposing)
    {
        if (!(_reader is null))
        {
            _reader.Invoke("cancel");
        }

        _reader?.Dispose();
        _status?.Dispose();
    }

    ...
}

Such a change would be a great improvement for scenarios like consuming async streams coming from servers.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions