// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO.Pipelines; using System.Threading; using System.Threading.Tasks; namespace Microsoft.AspNetCore.SignalR.Microbenchmarks.Shared { public class TestPipeWriter : PipeWriter { // huge buffer that should be large enough for writing any content private readonly byte[] _buffer = new byte[10000]; public bool ForceAsync { get; set; } public override void Advance(int bytes) { } public override Memory GetMemory(int sizeHint = 0) { return _buffer; } public override Span GetSpan(int sizeHint = 0) { return _buffer; } public override void OnReaderCompleted(Action callback, object state) { throw new NotImplementedException(); } public override void CancelPendingFlush() { throw new NotImplementedException(); } public override void Complete(Exception exception = null) { throw new NotImplementedException(); } public override ValueTask FlushAsync(CancellationToken cancellationToken = new CancellationToken()) { if (!ForceAsync) { return default; } return new ValueTask(ForceAsyncResult()); } public async Task ForceAsyncResult() { return await Task.FromResult(default).ForceAsync(); } } }