Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal partial class AsyncWebsocketMessageResultEnumerator : IAsyncEnumerator<
public ClientResult Current { get; private set; }
private readonly CancellationToken _cancellationToken;
private readonly WebSocket _webSocket;
private readonly byte[] _receiveBuffer;
private byte[] _receiveBuffer;

public AsyncWebsocketMessageResultEnumerator(WebSocket webSocket, CancellationToken cancellationToken)
{
Expand All @@ -26,12 +26,11 @@ public AsyncWebsocketMessageResultEnumerator(WebSocket webSocket, CancellationTo

public ValueTask DisposeAsync()
{
_webSocket?.Dispose();
if (_receiveBuffer is not null)
if (Interlocked.Exchange(ref _receiveBuffer, null) is byte[] toReturn)
{
ArrayPool<byte>.Shared.Return(_receiveBuffer);
ArrayPool<byte>.Shared.Return(toReturn);
}
return new ValueTask(Task.CompletedTask);
return default;
}

public async ValueTask<bool> MoveNextAsync()
Expand Down