/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Http/Http.Extensions/test/TestStream.cs
52 строки
2 KB
Martin Costello
Use non-generic TaskCompletionSource (#39835)
29 янв 2022, 03:32
Не верифицирован
29 янв 2022, 03:32
123d9b5
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Microsoft.AspNetCore.Http.Extensions.Tests; public class TestStream : Stream { public override bool CanRead { get; } public override bool CanSeek { get; } public override bool CanWrite { get; } public override long Length { get; } public override long Position { get; set; } public override void Flush() { throw new NotImplementedException(); } public override int Read(byte[] buffer, int offset, int count) { throw new NotImplementedException(); } public override long Seek(long offset, SeekOrigin origin) { throw new NotImplementedException(); } public override void SetLength(long value) { throw new NotImplementedException(); } public override void Write(byte[] buffer, int offset, int count) { throw new NotImplementedException(); } public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) { var tcs = new TaskCompletionSource<int>(); cancellationToken.Register(s => ((TaskCompletionSource<int>)s).SetCanceled(), tcs); return new ValueTask<int>(tcs.Task); } public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) { var tcs = new TaskCompletionSource(); cancellationToken.Register(s => ((TaskCompletionSource)s).SetCanceled(), tcs); return new ValueTask(tcs.Task); } }