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

Commit c7a9185

Browse files
committed
Hold reference to JoinableTaskContext
Simplify by holding a reference to JoinableTaskContext rather than JoinableTaskFactory.
1 parent a30eaae commit c7a9185

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

src/GitHub.App/Authentication/TwoFactorChallengeHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TwoFactorChallengeHandler : ReactiveObject, IDelegatingTwoFactorCha
2222
[ImportingConstructor]
2323
public TwoFactorChallengeHandler([Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext)
2424
{
25-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
25+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
2626
}
2727

2828
ILogin2FaViewModel twoFactorDialog;
@@ -41,7 +41,7 @@ public async Task<TwoFactorChallengeResult> HandleTwoFactorException(TwoFactorAu
4141
{
4242
Guard.ArgumentNotNull(exception, nameof(exception));
4343

44-
await JoinableTaskFactory.SwitchToMainThreadAsync();
44+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
4545

4646
var userError = new TwoFactorRequiredUserError(exception);
4747
var result = await twoFactorDialog.Show(userError);
@@ -58,10 +58,10 @@ public async Task<TwoFactorChallengeResult> HandleTwoFactorException(TwoFactorAu
5858

5959
public async Task ChallengeFailed(Exception exception)
6060
{
61-
await JoinableTaskFactory.SwitchToMainThreadAsync();
61+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
6262
twoFactorDialog.Cancel();
6363
}
6464

65-
JoinableTaskFactory JoinableTaskFactory { get; }
65+
JoinableTaskContext JoinableTaskContext { get; }
6666
}
6767
}

src/GitHub.App/Factories/ModelServiceFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ModelServiceFactory(
3232
this.apiClientFactory = apiClientFactory;
3333
this.hostCacheFactory = hostCacheFactory;
3434
this.avatarProvider = avatarProvider;
35-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
35+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
3636
}
3737

3838
public async Task<IModelService> CreateAsync(IConnection connection)
@@ -63,11 +63,11 @@ await hostCacheFactory.Create(connection.HostAddress),
6363

6464
public IModelService CreateBlocking(IConnection connection)
6565
{
66-
return JoinableTaskFactory.Run(() => CreateAsync(connection));
66+
return JoinableTaskContext.Factory.Run(() => CreateAsync(connection));
6767
}
6868

6969
public void Dispose() => cacheLock.Dispose();
7070

71-
JoinableTaskFactory JoinableTaskFactory { get; }
71+
JoinableTaskContext JoinableTaskContext { get; }
7272
}
7373
}

src/GitHub.App/Services/GitHubCredentialProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public GitHubCredentialProvider(IKeychain keychain, [Import(AllowDefault = true)
2424
Guard.ArgumentNotNull(keychain, nameof(keychain));
2525

2626
this.keychain = keychain;
27-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
27+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
2828
}
2929

3030
/// <summary>
@@ -40,7 +40,7 @@ public Credentials HandleCredentials(string url, string username, SupportedCrede
4040

4141
try
4242
{
43-
var credentials = JoinableTaskFactory.Run(async () => await keychain.Load(host));
43+
var credentials = JoinableTaskContext.Factory.Run(async () => await keychain.Load(host));
4444
return new UsernamePasswordCredentials
4545
{
4646
Username = credentials.Item1,
@@ -54,6 +54,6 @@ public Credentials HandleCredentials(string url, string username, SupportedCrede
5454
}
5555
}
5656

57-
JoinableTaskFactory JoinableTaskFactory { get; }
57+
JoinableTaskContext JoinableTaskContext { get; }
5858
}
5959
}

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public RepositoryCloneService(
6060
this.gitHubContextService = gitHubContextService;
6161
this.usageTracker = usageTracker;
6262
dte = new Lazy<EnvDTE.DTE>(() => sp.GetService<EnvDTE.DTE>());
63-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
63+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
6464

6565
defaultClonePath = GetLocalClonePathFromGitProvider(operatingSystem.Environment.GetUserRepositoriesPath());
6666
}
@@ -212,7 +212,7 @@ public async Task CloneRepository(
212212
{
213213
await TaskScheduler.Default;
214214
operatingSystem.Directory.CreateDirectory(repositoryPath);
215-
await JoinableTaskFactory.SwitchToMainThreadAsync();
215+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
216216
}
217217

218218
try
@@ -253,7 +253,7 @@ string GetLocalClonePathFromGitProvider(string fallbackPath)
253253

254254
public string DefaultClonePath { get { return defaultClonePath; } }
255255

256-
JoinableTaskFactory JoinableTaskFactory { get; }
256+
JoinableTaskContext JoinableTaskContext { get; }
257257

258258
class OrganizationAdapter
259259
{

src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public PullRequestDetailViewModel(
109109
this.viewViewModelFactory = viewViewModelFactory;
110110
this.gitService = gitService;
111111
this.openDocumentCommand = openDocumentCommand;
112-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
112+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
113113

114114
Files = files;
115115

@@ -475,7 +475,7 @@ public override async Task Refresh()
475475
{
476476
try
477477
{
478-
await JoinableTaskFactory.SwitchToMainThreadAsync();
478+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
479479

480480
Error = null;
481481
OperationError = null;
@@ -739,6 +739,6 @@ public UpdateCommandState(
739739
public int SubmodulesToSync { get; }
740740
}
741741

742-
JoinableTaskFactory JoinableTaskFactory { get; }
742+
JoinableTaskContext JoinableTaskContext { get; }
743743
}
744744
}

src/GitHub.VisualStudio/Services/LocalRepositories.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public class LocalRepositories : ILocalRepositories
2626
public LocalRepositories(IVSGitServices vsGitServices, [Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext)
2727
{
2828
this.vsGitServices = vsGitServices;
29-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
29+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
3030
}
3131

3232
/// <inheritdoc/>
3333
public async Task Refresh()
3434
{
3535
await TaskScheduler.Default;
3636
var list = vsGitServices.GetKnownRepositories();
37-
await JoinableTaskFactory.SwitchToMainThreadAsync();
37+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
3838

3939
repositories.Except(list).ToList().ForEach(x => repositories.Remove(x));
4040
list.Except(repositories).ToList().ForEach(x => repositories.Add(x));
@@ -46,6 +46,6 @@ readonly ObservableCollectionEx<LocalRepositoryModel> repositories
4646
/// <inheritdoc/>
4747
public IReadOnlyObservableCollection<LocalRepositoryModel> Repositories => repositories;
4848

49-
JoinableTaskFactory JoinableTaskFactory { get; }
49+
JoinableTaskContext JoinableTaskContext { get; }
5050
}
5151
}

src/GitHub.VisualStudio/Services/UsageService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public UsageService(IGitHubServiceProvider serviceProvider, IEnvironment environ
3737
{
3838
this.serviceProvider = serviceProvider;
3939
this.environment = environment;
40-
JoinableTaskFactory = joinableTaskContext?.Factory ?? ThreadHelper.JoinableTaskFactory;
40+
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
4141
}
4242

4343
public void Dispose()
@@ -138,7 +138,7 @@ async Task Initialize()
138138
{
139139
if (storePath == null)
140140
{
141-
await JoinableTaskFactory.SwitchToMainThreadAsync();
141+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
142142

143143
var program = serviceProvider.GetService<IProgram>();
144144

@@ -190,6 +190,6 @@ class UserData
190190
public Guid UserGuid { get; set; }
191191
}
192192

193-
JoinableTaskFactory JoinableTaskFactory { get; }
193+
JoinableTaskContext JoinableTaskContext { get; }
194194
}
195195
}

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public UsageTracker(
3636
this.gitHubServiceProvider = gitHubServiceProvider;
3737
this.service = service;
3838
this.userSettings = settings;
39-
JoinableTaskFactory = joinableTaskContext.Factory;
39+
JoinableTaskContext = joinableTaskContext;
4040
timer = StartTimer();
4141
}
4242

@@ -70,7 +70,7 @@ async Task Initialize()
7070

7171
// The services needed by the usage tracker are loaded when they are first needed to
7272
// improve the startup time of the extension.
73-
await JoinableTaskFactory.SwitchToMainThreadAsync();
73+
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
7474

7575
client = gitHubServiceProvider.TryGetService<IMetricsService>();
7676
connectionManager = gitHubServiceProvider.GetService<IConnectionManager>();
@@ -143,6 +143,6 @@ async Task<UsageModel> GetCurrentReport(UsageData data)
143143
return current;
144144
}
145145

146-
JoinableTaskFactory JoinableTaskFactory { get; }
146+
JoinableTaskContext JoinableTaskContext { get; }
147147
}
148148
}

0 commit comments

Comments
 (0)