solve 'edge' case and pass cancellation token

This commit is contained in:
Dennis Arfan 2025-08-01 22:13:13 +07:00
parent 0472bfe58e
commit d3dfdd6a74
15 changed files with 208 additions and 551 deletions

View file

@ -30,7 +30,7 @@ public static class ImageController
await tileManager
.CreateSection(dto)
.DangerousWriteToPipe(response.BodyWriter, dto.OutputScale, cancellationToken);
.WriteToPipe(response.BodyWriter, dto.OutputScale, cancellationToken);
await response.CompleteAsync();
}
@ -56,7 +56,7 @@ public static class ImageController
var scale = float.Clamp(480f / int.Max(section.Width, section.Height), 0.01f, 1f);
Console.WriteLine($"Generate random image for {coordinatePair} scale: {scale}");
await section.DangerousWriteToPipe(response.BodyWriter, scale, cancellationToken);
await section.WriteToPipe(response.BodyWriter, scale, cancellationToken);
await response.CompleteAsync();
}
}

View file

@ -15,19 +15,23 @@ public static class Utils
dto.CropSize![0],
dto.CropSize![1]);
public static async Task WriteToStream(this GridSection section, Stream stream, float? scale)
public static async Task WriteToStream(
this GridSection section,
Stream stream,
float? scale,
CancellationToken cancellationToken = default)
{
var imageCreator = new ImageCreator(section);
await imageCreator.WriteToStream(stream, scale!.Value);
using var imageCreator = new DangerousImageCreator(section);
await imageCreator.WriteToStream(stream, scale!.Value, cancellationToken);
}
public static async Task DangerousWriteToPipe(
public static async Task WriteToPipe(
this GridSection section,
PipeWriter pipeWriter,
float? scale,
CancellationToken cancellationToken = default)
{
var imageCreator = new DangerousImageCreator(section);
using var imageCreator = new DangerousImageCreator(section);
await imageCreator.WriteToPipe(pipeWriter, scale!.Value, cancellationToken);
}
}