Skip to content

Commit

Permalink
apply cancellation tokens and ConfigureAwait
Browse files Browse the repository at this point in the history
  • Loading branch information
j0nimost committed Oct 27, 2023
1 parent d0fcbc8 commit c1ed8fc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Kafa/Kafa.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ public static ReadOnlySpan<byte> Write<T>(List<T> entities, KafaOptions options
return pooledBufferWriter.WrittenAsSpan;
}

public static async ValueTask<Stream> WriteToStreamAsync<T>(List<T> entities, KafaOptions options = null)
public static async ValueTask<Stream> WriteToStreamAsync<T>(List<T> entities, KafaOptions options = null, CancellationToken token = default)

Check warning on line 101 in src/Kafa/Kafa.Stream.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
ArgumentNullException.ThrowIfNull(entities, nameof(entities));
var reflection = SetupOptions<T>(options);
var memoryStream = new MemoryStream();
using var bufferWriter = new KafaWriter(memoryStream, reflection.TypeInfo.KafaOptions);
reflection.GetProperties<T>(bufferWriter, entities);
await bufferWriter.FlushAsync();
await bufferWriter.FlushAsync(token).ConfigureAwait(false);
return memoryStream;
}

public static async ValueTask WriteToFileAsync<T>(List<T> entities, string path, KafaOptions options = null)
public static async ValueTask WriteToFileAsync<T>(List<T> entities, string path, KafaOptions options = null, CancellationToken token=default)

Check warning on line 112 in src/Kafa/Kafa.Stream.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
ArgumentNullException.ThrowIfNull(entities, nameof(entities));
ArgumentNullException.ThrowIfNull(path, nameof(path));
var reflection = SetupOptions<T>(options);
using var fs = new FileStream(path, FileMode.Create);
using var bufferWriter = new KafaWriter(fs, reflection.TypeInfo.KafaOptions);
reflection.GetProperties<T>(bufferWriter, entities);
await bufferWriter.FlushAsync();
await bufferWriter.FlushAsync(token).ConfigureAwait(false);
}

private static KafaReflection SetupOptions<T>(KafaOptions options)
Expand Down

0 comments on commit c1ed8fc

Please sign in to comment.