Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 18f08fd

Browse files
authored
Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#705)
Instead of Task.FromResult(0)
1 parent 22e5dfd commit 18f08fd

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

src/Microsoft.AspNetCore.Http.Abstractions/HttpResponse.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.IO;
66
using System.Threading.Tasks;
7+
using Microsoft.Extensions.Internal;
78

89
namespace Microsoft.AspNetCore.Http
910
{
@@ -16,7 +17,7 @@ public abstract class HttpResponse
1617
private static readonly Func<object, Task> _disposeDelegate = disposable =>
1718
{
1819
((IDisposable)disposable).Dispose();
19-
return Task.FromResult(0);
20+
return TaskCache.CompletedTask;
2021
};
2122

2223
/// <summary>

src/Microsoft.AspNetCore.Http.Abstractions/project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"type": "build",
2525
"version": "1.1.0-*"
2626
},
27+
"Microsoft.Extensions.TaskCache.Sources": {
28+
"version": "1.1.0-*",
29+
"type": "build"
30+
},
2731
"System.Text.Encodings.Web": "4.0.0-*"
2832
},
2933
"frameworks": {

src/Microsoft.AspNetCore.Http/Internal/ApplicationBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Threading.Tasks;
87
using Microsoft.AspNetCore.Http;
98
using Microsoft.AspNetCore.Http.Features;
109
using Microsoft.AspNetCore.Http.Internal;
10+
using Microsoft.Extensions.Internal;
1111

1212
namespace Microsoft.AspNetCore.Builder.Internal
1313
{
@@ -81,7 +81,7 @@ public RequestDelegate Build()
8181
RequestDelegate app = context =>
8282
{
8383
context.Response.StatusCode = 404;
84-
return Task.FromResult(0);
84+
return TaskCache.CompletedTask;
8585
};
8686

8787
foreach (var component in _components.Reverse())

src/Microsoft.AspNetCore.Http/project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"Microsoft.AspNetCore.WebUtilities": "1.1.0-*",
2525
"Microsoft.Extensions.ObjectPool": "1.1.0-*",
2626
"Microsoft.Extensions.Options": "1.1.0-*",
27+
"Microsoft.Extensions.TaskCache.Sources": {
28+
"version": "1.1.0-*",
29+
"type": "build"
30+
},
2731
"Microsoft.Net.Http.Headers": "1.1.0-*",
2832
"System.Buffers": "4.0.0-*"
2933
},

src/Microsoft.AspNetCore.Owin/OwinEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.AspNetCore.Http;
1818
using Microsoft.AspNetCore.Http.Features;
1919
using Microsoft.AspNetCore.Http.Features.Authentication;
20+
using Microsoft.Extensions.Internal;
2021

2122
namespace Microsoft.AspNetCore.Owin
2223
{
@@ -67,7 +68,7 @@ public OwinEnvironment(HttpContext context)
6768
feature.OnStarting(s =>
6869
{
6970
cb(s);
70-
return Task.FromResult(0);
71+
return TaskCache.CompletedTask;
7172
}, state);
7273
}))
7374
},

src/Microsoft.AspNetCore.Owin/WebSockets/WebSocketAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using System.Threading;
99
using System.Threading.Tasks;
10+
using Microsoft.Extensions.Internal;
1011

1112
namespace Microsoft.AspNetCore.Owin
1213
{
@@ -68,7 +69,7 @@ internal Task SendAsync(ArraySegment<byte> buffer, int messageType, bool endOfMe
6869
else if (messageType == 0x9 || messageType == 0xA)
6970
{
7071
// Ping & Pong, not allowed by the underlying APIs, silently discard.
71-
return Task.FromResult(0);
72+
return TaskCache.CompletedTask;
7273
}
7374

7475
return _webSocket.SendAsync(buffer, OpCodeToEnum(messageType), endOfMessage, cancel);

src/Microsoft.AspNetCore.Owin/project.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
"xmlDoc": true
2222
},
2323
"dependencies": {
24-
"Microsoft.AspNetCore.Http": "1.1.0-*"
24+
"Microsoft.AspNetCore.Http": "1.1.0-*",
25+
"Microsoft.Extensions.TaskCache.Sources": {
26+
"version": "1.1.0-*",
27+
"type": "build"
28+
}
2529
},
2630
"frameworks": {
2731
"net451": {},

0 commit comments

Comments
 (0)