//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.ChatServer.Tests;
using System.IO.Pipelines;
///
/// Extensions for the , helpful for testing.
///
internal static class PipeWriterExtension
{
///
/// Flushes and waits until the written bytes are flushed.
///
/// The pipe writer.
/// The data which should be written.
public static async Task WriteAndWaitForFlushAsync(this PipeWriter pipeWriter, ReadOnlyMemory data)
{
await pipeWriter.WriteAsync(data).ConfigureAwait(false);
await pipeWriter.WaitForFlushAsync().ConfigureAwait(false);
}
///
/// Waits until all are flushed.
///
/// The pipe writer.
public static async Task WaitForFlushAsync(this PipeWriter pipeWriter)
{
do
{
await Task.Delay(200).ConfigureAwait(false);
}
while (pipeWriter.UnflushedBytes > 0);
await Task.Delay(200).ConfigureAwait(false);
}
}