Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #115 by using the passed CancellationToken in MemoryBufferWriter #117

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
Fixes #115 by using the passed CancellationToken in MemoryBufferWriter
danielwertheim committed Mar 28, 2020
commit 9ddc9d8304f90ed38e3597f42e1bf9d03f3ceea9
Original file line number Diff line number Diff line change
@@ -140,10 +140,10 @@ public override Task CopyToAsync(Stream destination, int bufferSize, Cancellatio
if (_completedSegments == null)
{
// There is only one segment so write without awaiting.
return destination.WriteAsync(_currentSegment, 0, _position);
return destination.WriteAsync(_currentSegment, 0, _position, cancellationToken);
}

return CopyToSlowAsync(destination);
return CopyToSlowAsync(destination, cancellationToken);
}

private void EnsureCapacity(int sizeHint)
@@ -184,7 +184,7 @@ private void AddSegment(int sizeHint = 0)
_position = 0;
}

private async Task CopyToSlowAsync(Stream destination)
private async Task CopyToSlowAsync(Stream destination, CancellationToken cancellationToken)
{
if (_completedSegments != null)
{
@@ -193,11 +193,11 @@ private async Task CopyToSlowAsync(Stream destination)
for (var i = 0; i < count; i++)
{
var segment = _completedSegments[i];
await destination.WriteAsync(segment.Buffer, 0, segment.Length);
await destination.WriteAsync(segment.Buffer, 0, segment.Length, cancellationToken);
}
}

await destination.WriteAsync(_currentSegment, 0, _position);
await destination.WriteAsync(_currentSegment, 0, _position, cancellationToken);
}

public byte[] ToArray()