Skip to content

Commit fd1e082

Browse files
authored
Change callbacks to virtual from being abstract (dotnet/corefx#39526)
- Obsolete the callbacks as well Commit migrated from dotnet/corefx@51cd784
1 parent b0517c3 commit fd1e082

14 files changed

Lines changed: 34 additions & 31 deletions

src/libraries/System.IO.Pipelines/ref/System.IO.Pipelines.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ protected PipeReader() { }
5151
public virtual System.Threading.Tasks.Task CopyToAsync(System.IO.Pipelines.PipeWriter destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5252
public virtual System.Threading.Tasks.Task CopyToAsync(System.IO.Stream destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
5353
public static System.IO.Pipelines.PipeReader Create(System.IO.Stream stream, System.IO.Pipelines.StreamPipeReaderOptions readerOptions = null) { throw null; }
54-
public abstract void OnWriterCompleted(System.Action<System.Exception, object> callback, object state);
54+
[System.Obsolete("OnWriterCompleted may not be invoked on all implementations of PipeReader. This will be removed in a future release.")]
55+
public virtual void OnWriterCompleted(System.Action<System.Exception, object> callback, object state) { }
5556
public abstract System.Threading.Tasks.ValueTask<System.IO.Pipelines.ReadResult> ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
5657
public abstract bool TryRead(out System.IO.Pipelines.ReadResult result);
5758
}
@@ -75,7 +76,8 @@ protected PipeWriter() { }
7576
public abstract System.Threading.Tasks.ValueTask<System.IO.Pipelines.FlushResult> FlushAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
7677
public abstract System.Memory<byte> GetMemory(int sizeHint = 0);
7778
public abstract System.Span<byte> GetSpan(int sizeHint = 0);
78-
public abstract void OnReaderCompleted(System.Action<System.Exception, object> callback, object state);
79+
[System.Obsolete("OnReaderCompleted may not be invoked on all implementations of PipeWriter. This will be removed in a future release.")]
80+
public virtual void OnReaderCompleted(System.Action<System.Exception, object> callback, object state) { }
7981
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; }
8082
}
8183
public readonly partial struct ReadResult

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeReader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public DefaultPipeReader(Pipe pipe)
3434

3535
public override void Complete(Exception exception = null) => _pipe.CompleteReader(exception);
3636

37+
#pragma warning disable CS0672 // Member overrides obsolete member
3738
public override void OnWriterCompleted(Action<Exception, object> callback, object state) => _pipe.OnWriterCompleted(callback, state);
39+
#pragma warning restore CS0672 // Member overrides obsolete member
3840

3941
public ValueTaskSourceStatus GetStatus(short token) => _pipe.GetReadAsyncStatus();
4042

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.DefaultPipeWriter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public DefaultPipeWriter(Pipe pipe)
2626

2727
public override void CancelPendingFlush() => _pipe.CancelPendingFlush();
2828

29+
#pragma warning disable CS0672 // Member overrides obsolete member
2930
public override void OnReaderCompleted(Action<Exception, object> callback, object state) => _pipe.OnReaderCompleted(callback, state);
31+
#pragma warning restore CS0672 // Member overrides obsolete member
3032

3133
public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default) => _pipe.FlushAsync(cancellationToken);
3234

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeReader.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ public virtual ValueTask CompleteAsync(Exception exception = null)
100100
/// <summary>
101101
/// Registers a callback that gets executed when the <see cref="PipeWriter"/> side of the pipe is completed
102102
/// </summary>
103-
public abstract void OnWriterCompleted(Action<Exception, object> callback, object state);
103+
[Obsolete("OnWriterCompleted may not be invoked on all implementations of PipeReader. This will be removed in a future release.")]
104+
public virtual void OnWriterCompleted(Action<Exception, object> callback, object state)
105+
{
106+
107+
}
104108

105109

106110
/// <summary>

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeWriter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public virtual ValueTask CompleteAsync(Exception exception = null)
4646
/// <summary>
4747
/// Registers a callback that gets executed when the <see cref="PipeReader"/> side of the pipe is completed
4848
/// </summary>
49-
public abstract void OnReaderCompleted(Action<Exception, object> callback, object state);
49+
[Obsolete("OnReaderCompleted may not be invoked on all implementations of PipeWriter. This will be removed in a future release.")]
50+
public virtual void OnReaderCompleted(Action<Exception, object> callback, object state)
51+
{
52+
53+
}
5054

5155
/// <summary>
5256
/// Makes bytes written available to <see cref="PipeReader"/> and runs <see cref="PipeReader.ReadAsync"/> continuation.

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ public override void Complete(Exception exception = null)
187187
}
188188
}
189189

190-
/// <inheritdoc />
191-
public override void OnWriterCompleted(Action<Exception, object> callback, object state)
192-
{
193-
}
194-
195190
/// <inheritdoc />
196191
public override async ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
197192
{

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ public override async ValueTask CompleteAsync(Exception exception = null)
247247
}
248248
}
249249

250-
/// <inheritdoc />
251-
public override void OnReaderCompleted(Action<Exception, object> callback, object state)
252-
{
253-
}
254-
255250
/// <inheritdoc />
256251
public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default)
257252
{

src/libraries/System.IO.Pipelines/tests/PipeCompletionCallbacksTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#pragma warning disable CS0618 // Type or member is obsolete
6+
57
using System.Runtime.CompilerServices;
68
using System.Threading.Tasks;
79
using Xunit;

src/libraries/System.IO.Pipelines/tests/PipePoolTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ public async Task OnWriterCompletedCalledAfterBlocksReturned()
184184

185185
Assert.Equal(1, pool.CurrentlyRentedBlocks);
186186

187+
#pragma warning disable CS0618 // Type or member is obsolete
187188
pipe.Reader.OnWriterCompleted((exception, o) => Assert.Equal(0, pool.CurrentlyRentedBlocks), null);
189+
#pragma warning restore CS0618 // Type or member is obsolete
188190

189191
pipe.Reader.Complete();
190192
pipe.Writer.Complete();
@@ -200,7 +202,9 @@ public async Task OnReaderCompletedCalledAfterBlocksReturned()
200202

201203
Assert.Equal(1, pool.CurrentlyRentedBlocks);
202204

205+
#pragma warning disable CS0618 // Type or member is obsolete
203206
pipe.Writer.OnReaderCompleted((exception, o) => Assert.Equal(0, pool.CurrentlyRentedBlocks), null);
207+
#pragma warning restore CS0618 // Type or member is obsolete
204208

205209
pipe.Writer.Complete();
206210
pipe.Reader.Complete();

src/libraries/System.IO.Pipelines/tests/PipeReaderStreamTests.nonnetstandard.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public async Task DisposingPipeReaderStreamCompletesPipeReader(bool dataInPipe)
3131
}
3232

3333
var readerCompletedTask = new TaskCompletionSource<bool>();
34+
#pragma warning disable CS0618 // Type or member is obsolete
3435
pipe.Writer.OnReaderCompleted(delegate { readerCompletedTask.SetResult(true); }, null);
36+
#pragma warning restore CS0618 // Type or member is obsolete
3537

3638
// Call Dispose{Async} multiple times; all should succeed.
3739
for (int i = 0; i < 2; i++)
@@ -309,11 +311,6 @@ public override void Complete(Exception exception = null)
309311
throw new NotImplementedException();
310312
}
311313

312-
public override void OnWriterCompleted(Action<Exception, object> callback, object state)
313-
{
314-
throw new NotImplementedException();
315-
}
316-
317314
public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
318315
{
319316
// Returns a ReadResult with no buffer and with IsCompleted and IsCancelled false
@@ -332,7 +329,6 @@ public class NotImplementedPipeReader : PipeReader
332329
public override void AdvanceTo(SequencePosition consumed, SequencePosition examined) => throw new NotImplementedException();
333330
public override void CancelPendingRead() => throw new NotImplementedException();
334331
public override void Complete(Exception exception = null) => throw new NotImplementedException();
335-
public override void OnWriterCompleted(Action<Exception, object> callback, object state) => throw new NotImplementedException();
336332
public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();
337333
public override bool TryRead(out ReadResult result) => throw new NotImplementedException();
338334
}
@@ -362,11 +358,6 @@ public override void Complete(Exception exception = null)
362358
throw new NotImplementedException();
363359
}
364360

365-
public override void OnWriterCompleted(Action<Exception, object> callback, object state)
366-
{
367-
throw new NotImplementedException();
368-
}
369-
370361
public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
371362
{
372363
ReadCalled = true;

0 commit comments

Comments
 (0)