Change callbacks to virtual from being abstract (dotnet/corefx#39526)
authorDavid Fowler <davidfowl@gmail.com>
Tue, 16 Jul 2019 17:35:33 +0000 (10:35 -0700)
committerGitHub <noreply@github.com>
Tue, 16 Jul 2019 17:35:33 +0000 (10:35 -0700)
- Obsolete the callbacks as well

Commit migrated from https://github.com/dotnet/corefx/commit/51cd78434953683040f93e69ed2a889e476f5cac

14 files changed:
src/libraries/System.IO.Pipelines/ref/System.IO.Pipelines.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeReader.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeWriter.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriter.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs
src/libraries/System.IO.Pipelines/tests/PipeCompletionCallbacksTests.cs
src/libraries/System.IO.Pipelines/tests/PipePoolTests.cs
src/libraries/System.IO.Pipelines/tests/PipeReaderStreamTests.nonnetstandard.cs
src/libraries/System.IO.Pipelines/tests/PipeWriterStreamTests.nonnetstandard.cs
src/libraries/System.IO.Pipelines/tests/SchedulerFacts.cs
src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs
src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs

index 58a5b39..08de47c 100644 (file)
@@ -51,7 +51,8 @@ namespace System.IO.Pipelines
         public virtual System.Threading.Tasks.Task CopyToAsync(System.IO.Pipelines.PipeWriter destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
         public virtual System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
         public static System.IO.Pipelines.PipeReader Create(System.IO.Stream stream, System.IO.Pipelines.StreamPipeReaderOptions readerOptions = null) { throw null; }
-        public abstract void OnWriterCompleted(System.Action<System.Exception, object> callback, object state);
+        [System.Obsolete("OnWriterCompleted may not be invoked on all implementations of PipeReader. This will be removed in a future release.")]
+        public virtual void OnWriterCompleted(System.Action<System.Exception, object> callback, object state) { }
         public abstract System.Threading.Tasks.ValueTask<System.IO.Pipelines.ReadResult> ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
         public abstract bool TryRead(out System.IO.Pipelines.ReadResult result);
     }
@@ -75,7 +76,8 @@ namespace System.IO.Pipelines
         public abstract System.Threading.Tasks.ValueTask<System.IO.Pipelines.FlushResult> FlushAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
         public abstract System.Memory<byte> GetMemory(int sizeHint = 0);
         public abstract System.Span<byte> GetSpan(int sizeHint = 0);
-        public abstract void OnReaderCompleted(System.Action<System.Exception, object> callback, object state);
+        [System.Obsolete("OnReaderCompleted may not be invoked on all implementations of PipeWriter. This will be removed in a future release.")]
+        public virtual void OnReaderCompleted(System.Action<System.Exception, object> callback, object state) { }
         public virtual System.Threading.Tasks.ValueTask<System.IO.Pipelines.FlushResult> WriteAsync(System.ReadOnlyMemory<byte> source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
     }
     public readonly partial struct ReadResult
index f11b5db..2579397 100644 (file)
@@ -34,7 +34,9 @@ namespace System.IO.Pipelines
 
             public override void Complete(Exception exception = null) => _pipe.CompleteReader(exception);
 
+#pragma warning disable CS0672 // Member overrides obsolete member
             public override void OnWriterCompleted(Action<Exception, object> callback, object state) => _pipe.OnWriterCompleted(callback, state);
+#pragma warning restore CS0672 // Member overrides obsolete member
 
             public ValueTaskSourceStatus GetStatus(short token) => _pipe.GetReadAsyncStatus();
 
index 5546eb8..94077bb 100644 (file)
@@ -26,7 +26,9 @@ namespace System.IO.Pipelines
 
             public override void CancelPendingFlush() => _pipe.CancelPendingFlush();
 
+#pragma warning disable CS0672 // Member overrides obsolete member
             public override void OnReaderCompleted(Action<Exception, object> callback, object state) => _pipe.OnReaderCompleted(callback, state);
+#pragma warning restore CS0672 // Member overrides obsolete member
 
             public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default) => _pipe.FlushAsync(cancellationToken);
 
index d3d6cd5..6dd5be2 100644 (file)
@@ -100,7 +100,11 @@ namespace System.IO.Pipelines
         /// <summary>
         /// Registers a callback that gets executed when the <see cref="PipeWriter"/> side of the pipe is completed
         /// </summary>
-        public abstract void OnWriterCompleted(Action<Exception, object> callback, object state);
+        [Obsolete("OnWriterCompleted may not be invoked on all implementations of PipeReader. This will be removed in a future release.")]
+        public virtual void OnWriterCompleted(Action<Exception, object> callback, object state)
+        {
+
+        }
 
 
         /// <summary>
index 3be0f29..960e257 100644 (file)
@@ -46,7 +46,11 @@ namespace System.IO.Pipelines
         /// <summary>
         /// Registers a callback that gets executed when the <see cref="PipeReader"/> side of the pipe is completed
         /// </summary>
-        public abstract void OnReaderCompleted(Action<Exception, object> callback, object state);
+        [Obsolete("OnReaderCompleted may not be invoked on all implementations of PipeWriter. This will be removed in a future release.")]
+        public virtual void OnReaderCompleted(Action<Exception, object> callback, object state)
+        {
+
+        }
 
         /// <summary>
         /// Makes bytes written available to <see cref="PipeReader"/> and runs <see cref="PipeReader.ReadAsync"/> continuation.
index 58e3e5c..340c13e 100644 (file)
@@ -188,11 +188,6 @@ namespace System.IO.Pipelines
         }
 
         /// <inheritdoc />
-        public override void OnWriterCompleted(Action<Exception, object> callback, object state)
-        {
-        }
-
-        /// <inheritdoc />
         public override async ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
         {
             // TODO ReadyAsync needs to throw if there are overlapping reads.
index f242874..dd81627 100644 (file)
@@ -248,11 +248,6 @@ namespace System.IO.Pipelines
         }
 
         /// <inheritdoc />
-        public override void OnReaderCompleted(Action<Exception, object> callback, object state)
-        {
-        }
-
-        /// <inheritdoc />
         public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default)
         {
             if (_bytesBuffered == 0)
index 9a23b41..c56974b 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#pragma warning disable CS0618 // Type or member is obsolete
+
 using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
 using Xunit;
index ce49a55..64c2b55 100644 (file)
@@ -184,7 +184,9 @@ namespace System.IO.Pipelines.Tests
 
             Assert.Equal(1, pool.CurrentlyRentedBlocks);
 
+#pragma warning disable CS0618 // Type or member is obsolete
             pipe.Reader.OnWriterCompleted((exception, o) => Assert.Equal(0, pool.CurrentlyRentedBlocks), null);
+#pragma warning restore CS0618 // Type or member is obsolete
 
             pipe.Reader.Complete();
             pipe.Writer.Complete();
@@ -200,7 +202,9 @@ namespace System.IO.Pipelines.Tests
 
             Assert.Equal(1, pool.CurrentlyRentedBlocks);
 
+#pragma warning disable CS0618 // Type or member is obsolete
             pipe.Writer.OnReaderCompleted((exception, o) => Assert.Equal(0, pool.CurrentlyRentedBlocks), null);
+#pragma warning restore CS0618 // Type or member is obsolete
 
             pipe.Writer.Complete();
             pipe.Reader.Complete();
index c3e2af1..0a94358 100644 (file)
@@ -31,7 +31,9 @@ namespace System.IO.Pipelines.Tests
             }
 
             var readerCompletedTask = new TaskCompletionSource<bool>();
+#pragma warning disable CS0618 // Type or member is obsolete
             pipe.Writer.OnReaderCompleted(delegate { readerCompletedTask.SetResult(true); }, null);
+#pragma warning restore CS0618 // Type or member is obsolete
 
             // Call Dispose{Async} multiple times; all should succeed.
             for (int i = 0; i < 2; i++)
@@ -309,11 +311,6 @@ namespace System.IO.Pipelines.Tests
                 throw new NotImplementedException();
             }
 
-            public override void OnWriterCompleted(Action<Exception, object> callback, object state)
-            {
-                throw new NotImplementedException();
-            }
-
             public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
             {
                 // Returns a ReadResult with no buffer and with IsCompleted and IsCancelled false
@@ -332,7 +329,6 @@ namespace System.IO.Pipelines.Tests
             public override void AdvanceTo(SequencePosition consumed, SequencePosition examined) => throw new NotImplementedException();
             public override void CancelPendingRead() => throw new NotImplementedException();
             public override void Complete(Exception exception = null) => throw new NotImplementedException();
-            public override void OnWriterCompleted(Action<Exception, object> callback, object state) => throw new NotImplementedException();
             public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();
             public override bool TryRead(out ReadResult result) => throw new NotImplementedException();
         }
@@ -362,11 +358,6 @@ namespace System.IO.Pipelines.Tests
                 throw new NotImplementedException();
             }
 
-            public override void OnWriterCompleted(Action<Exception, object> callback, object state)
-            {
-                throw new NotImplementedException();
-            }
-
             public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
             {
                 ReadCalled = true;
index bea4abd..e136a23 100644 (file)
@@ -23,7 +23,9 @@ namespace System.IO.Pipelines.Tests
             Stream s = pipe.Writer.AsStream();
 
             var writerCompletedTask = new TaskCompletionSource<bool>();
+#pragma warning disable CS0618 // Type or member is obsolete
             pipe.Reader.OnWriterCompleted(delegate { writerCompletedTask.SetResult(true); }, null);
+#pragma warning restore CS0618 // Type or member is obsolete
 
             // Call Dispose{Async} multiple times; all should succeed.
             for (int i = 0; i < 2; i++)
@@ -212,11 +214,6 @@ namespace System.IO.Pipelines.Tests
                 throw new NotImplementedException();
             }
 
-            public override void OnReaderCompleted(Action<Exception, object> callback, object state)
-            {
-                throw new NotImplementedException();
-            }
-
             public override ValueTask<FlushResult> WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
             {
                 WriteAsyncCalled = true;
@@ -236,7 +233,6 @@ namespace System.IO.Pipelines.Tests
             public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();
             public override Memory<byte> GetMemory(int sizeHint = 0) => throw new NotImplementedException();
             public override Span<byte> GetSpan(int sizeHint = 0) => throw new NotImplementedException();
-            public override void OnReaderCompleted(Action<Exception, object> callback, object state) => throw new NotImplementedException();
         }
 
         public static IEnumerable<object[]> WriteCalls
index 8312cb3..905b318 100644 (file)
@@ -517,12 +517,14 @@ namespace System.IO.Pipelines.Tests
             Task reading = ExecuteOnNonThreadPoolThread(DoRead);
 
             PipeWriter buffer = pipe.Writer;
+#pragma warning disable CS0618 // Type or member is obsolete
             pipe.Writer.OnReaderCompleted((state, exception) =>
             {
                 callbackRan = true;
                 Assert.True(Thread.CurrentThread.IsThreadPoolThread);
             },
             null);
+#pragma warning restore CS0618 // Type or member is obsolete
 
             buffer.Write(Encoding.UTF8.GetBytes("Hello World"));
             await buffer.FlushAsync();
index 61359cd..c0ce8a3 100644 (file)
@@ -486,7 +486,9 @@ namespace System.IO.Pipelines.Tests
         {
             bool fired = false;
             PipeReader reader = PipeReader.Create(Stream.Null);
+#pragma warning disable CS0618 // Type or member is obsolete
             reader.OnWriterCompleted((_, __) => { fired = true; }, null);
+#pragma warning restore CS0618 // Type or member is obsolete
             reader.Complete();
             Assert.False(fired);
         }
index 555f3d8..e40d189 100644 (file)
@@ -511,7 +511,9 @@ namespace System.IO.Pipelines.Tests
         {
             bool fired = false;
             PipeWriter writer = PipeWriter.Create(Stream.Null);
+#pragma warning disable CS0618 // Type or member is obsolete
             writer.OnReaderCompleted((_, __) => { fired = true; }, null);
+#pragma warning restore CS0618 // Type or member is obsolete
             writer.Complete();
             Assert.False(fired);
         }