Completed Task opt
This commit is contained in:
parent
9d19eed88f
commit
278bd9c962
|
|
@ -2,16 +2,15 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||
{
|
||||
public class NoOpConnectionFilter : IConnectionFilter
|
||||
{
|
||||
private static Task _empty = Task.FromResult<object>(null);
|
||||
|
||||
public Task OnConnection(ConnectionFilterContext context)
|
||||
{
|
||||
return _empty;
|
||||
return TaskUtilities.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.IO;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Server.Kestrel.Http;
|
||||
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||
{
|
||||
|
|
@ -17,8 +18,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
|||
/// </summary>
|
||||
public class SocketInputStream : Stream
|
||||
{
|
||||
private static Task _emptyTask = Task.FromResult<object>(null);
|
||||
|
||||
private readonly SocketInput _socketInput;
|
||||
|
||||
public SocketInputStream(SocketInput socketInput)
|
||||
|
|
@ -85,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
|||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
|
||||
{
|
||||
Write(buffer, offset, count);
|
||||
return _emptyTask;
|
||||
return TaskUtilities.CompletedTask;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ using System.IO;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Server.Kestrel.Http;
|
||||
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Server.Kestrel.Filter
|
||||
{
|
||||
public class StreamSocketOutput : ISocketOutput
|
||||
{
|
||||
private static readonly Task _emptyTask = Task.FromResult<object>(null);
|
||||
|
||||
private readonly Stream _outputStream;
|
||||
|
||||
public StreamSocketOutput(Stream outputStream)
|
||||
|
|
@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
|
|||
{
|
||||
// TODO: Use _outputStream.WriteAsync
|
||||
_outputStream.Write(buffer.Array, buffer.Offset, buffer.Count);
|
||||
return _emptyTask;
|
||||
return TaskUtilities.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
|
|||
{
|
||||
public static class TaskUtilities
|
||||
{
|
||||
public static Task CompletedTask = NewCompletedTask();
|
||||
|
||||
private static Task NewCompletedTask()
|
||||
{
|
||||
var tcs = new TaskCompletionSource<int>();
|
||||
tcs.SetResult(0);
|
||||
return tcs.Task;
|
||||
}
|
||||
#if DOTNET5_4 || DNXCORE50
|
||||
public static Task CompletedTask = Task.CompletedTask;
|
||||
#else
|
||||
public static Task CompletedTask = Task.FromResult<object>(null);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue