Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 415e7dd

Browse files
Changing code to use Task.Run over TaskScheduler.Default
1 parent 0f46686 commit 415e7dd

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/GitHub.Api/GraphQLClient.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using GitHub.Extensions;
11-
using Microsoft.VisualStudio.Threading;
1211
using Octokit.GraphQL;
1312
using Octokit.GraphQL.Core;
1413

@@ -28,12 +27,10 @@ public GraphQLClient(
2827
this.cache = cache;
2928
}
3029

31-
public async Task ClearCache(string regionName)
30+
public Task ClearCache(string regionName)
3231
{
3332
// Switch to background thread because FileCache does not provide an async API.
34-
await TaskScheduler.Default;
35-
36-
cache.ClearRegion(GetFullRegionName(regionName));
33+
return Task.Run(() => cache.ClearRegion(GetFullRegionName(regionName)));
3734
}
3835

3936
public Task<T> Run<T>(
@@ -131,28 +128,29 @@ public CachingWrapper(
131128

132129
public Uri Uri => owner.connection.Uri;
133130

134-
public async Task<string> Run(string query, CancellationToken cancellationToken = default)
131+
public Task<string> Run(string query, CancellationToken cancellationToken = default)
135132
{
136133
// Switch to background thread because FileCache does not provide an async API.
137-
await TaskScheduler.Default;
138-
139-
var hash = GetHash(query);
140-
141-
if (refresh)
134+
return Task.Run(async () =>
142135
{
143-
owner.cache.Remove(hash, regionName);
144-
}
136+
var hash = GetHash(query);
145137

146-
var data = (string)owner.cache.Get(hash, regionName);
138+
if (refresh)
139+
{
140+
owner.cache.Remove(hash, regionName);
141+
}
147142

148-
if (data != null)
149-
{
150-
return data;
151-
}
143+
var data = (string) owner.cache.Get(hash, regionName);
144+
145+
if (data != null)
146+
{
147+
return data;
148+
}
152149

153-
var result = await owner.connection.Run(query, cancellationToken);
154-
owner.cache.Add(hash, result, DateTimeOffset.Now + cacheDuration, regionName);
155-
return result;
150+
var result = await owner.connection.Run(query, cancellationToken);
151+
owner.cache.Add(hash, result, DateTimeOffset.Now + cacheDuration, regionName);
152+
return result;
153+
}, cancellationToken);
156154
}
157155
}
158156
}

0 commit comments

Comments
 (0)