Repository: dotnet/runtime
File: src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Implementation.Adapters.cs (C#)

Code before:
        {
            ValueTask<int> ReadAsync(Memory<byte> buffer);
            ValueTask WriteAsync(byte[] buffer, int offset, int count);
            ValueTask LockAsync(TaskCompletionSource<bool> waiter);
            CancellationToken CancellationToken { get; }
        }

        private readonly struct AsyncSslIOAdapter : ISslIOAdapter
        {
            private readonly SslStream _sslStream;
            private readonly CancellationToken _cancellationToken;

            public AsyncSslIOAdapter(SslStream sslStream, CancellationToken cancellationToken)
            {
                _cancellationToken = cancellationToken;
                _sslStream = sslStream;
            }

            public ValueTask<int> ReadAsync(Memory<byte> buffer) => _sslStream.InnerStream.ReadAsync(buffer, _cancellationToken);

            public ValueTask WriteAsync(byte[] buffer, int offset, int count) => _sslStream.InnerStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), _cancellationToken);

            public async ValueTask LockAsync(TaskCompletionSource<bool> waiter)
            {
                await waiter.Task.ConfigureAwait(false);
            }

            public CancellationToken CancellationToken => _cancellationToken;
        }

        private readonly struct SyncSslIOAdapter : ISslIOAdapter
        {
            private readonly SslStream _sslStream;

            public SyncSslIOAdapter(SslStream sslStream) => _sslStream = sslStream;

            public ValueTask<int> ReadAsync(Memory<byte> buffer) => new ValueTask<int>(_sslStream.InnerStream.Read(buffer.Span));

            public ValueTask WriteAsync(byte[] buffer, int offset, int count)
            {
                _sslStream.InnerStream.Write(buffer, offset, count);
                return default;
            }

            public ValueTask LockAsync(TaskCompletionSource<bool> waiter)
            {
                waiter.Task.Wait();
                return default;
            }

            public CancellationToken CancellationToken => default;

Review comment (suggestion):
This shouldn't be an async method. And since no implementations of it benefit from ValueTask, just change the result type to be Task, then change the implementation to return waiter.Task.
```suggestion
            public Task LockAsync(TaskCompletionSource<bool> waiter) => waiter.Task;
```

Code after:
        {
            ValueTask<int> ReadAsync(Memory<byte> buffer);
            ValueTask WriteAsync(byte[] buffer, int offset, int count);
            Task WaitAsync(TaskCompletionSource<bool> waiter);
            CancellationToken CancellationToken { get; }
        }

        private readonly struct AsyncSslIOAdapter : ISslIOAdapter
        {
            private readonly SslStream _sslStream;
            private readonly CancellationToken _cancellationToken;

            public AsyncSslIOAdapter(SslStream sslStream, CancellationToken cancellationToken)
            {
                _cancellationToken = cancellationToken;
                _sslStream = sslStream;
            }

            public ValueTask<int> ReadAsync(Memory<byte> buffer) => _sslStream.InnerStream.ReadAsync(buffer, _cancellationToken);

            public ValueTask WriteAsync(byte[] buffer, int offset, int count) => _sslStream.InnerStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), _cancellationToken);

            public Task WaitAsync(TaskCompletionSource<bool> waiter) => waiter.Task;

            public CancellationToken CancellationToken => _cancellationToken;
        }

        private readonly struct SyncSslIOAdapter : ISslIOAdapter
        {
            private readonly SslStream _sslStream;

            public SyncSslIOAdapter(SslStream sslStream) => _sslStream = sslStream;

            public ValueTask<int> ReadAsync(Memory<byte> buffer) => new ValueTask<int>(_sslStream.InnerStream.Read(buffer.Span));

            public ValueTask WriteAsync(byte[] buffer, int offset, int count)
            {
                _sslStream.InnerStream.Write(buffer, offset, count);
                return default;
            }

            public Task WaitAsync(TaskCompletionSource<bool> waiter)
            {
                waiter.Task.Wait();
                return Task.CompletedTask;
            }

            public CancellationToken CancellationToken => default;
        }
    }
}