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

Commit 295bcbd

Browse files
committed
Make Reload reentrant
1 parent d67e4f4 commit 295bcbd

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/GitHub.VisualStudio/UI/Views/GitHubPaneViewModel.cs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using ReactiveUI;
2020
using System.Collections.Generic;
2121
using System.Threading.Tasks;
22+
using System.Diagnostics;
2223

2324
namespace GitHub.VisualStudio.UI.Views
2425
{
@@ -40,6 +41,7 @@ public class GitHubPaneViewModel : TeamExplorerItemBase, IGitHubPaneViewModel
4041
bool navigatingViaArrows;
4142
bool disabled;
4243
Microsoft.VisualStudio.Shell.OleMenuCommand back, forward, refresh;
44+
int latestReloadCallId;
4345

4446
[ImportingConstructor]
4547
public GitHubPaneViewModel(ISimpleApiClientFactory apiFactory, ITeamExplorerServiceHolder holder,
@@ -110,22 +112,52 @@ protected override void RepoChanged(bool changed)
110112
Reload().Forget();
111113
}
112114

115+
/// <summary>
116+
/// This method is reentrant, so all await calls need to be done before
117+
/// any actions are performed on the data. More recent calls to this method
118+
/// will cause previous calls pending on await calls to exit early.
119+
/// </summary>
120+
/// <returns></returns>
113121
async Task Reload([AllowNull] ViewWithData data = null, bool navigating = false)
114122
{
123+
if (!initialized)
124+
return;
125+
126+
latestReloadCallId++;
127+
var reloadCallId = latestReloadCallId;
128+
115129
navigatingViaArrows = navigating;
116130

117131
if (!IsGitHubRepo.HasValue)
118-
IsGitHubRepo = await IsAGitHubRepo();
132+
{
133+
var isGitHubRepo = await IsAGitHubRepo();
134+
if (reloadCallId != latestReloadCallId)
135+
return;
136+
137+
IsGitHubRepo = isGitHubRepo;
138+
}
139+
140+
var connection = await connectionManager.LookupConnection(ActiveRepo);
141+
if (reloadCallId != latestReloadCallId)
142+
return;
143+
144+
if (connection == null)
145+
IsLoggedIn = false;
146+
else
147+
{
148+
var isLoggedIn = await connection.IsLoggedIn(hosts);
149+
if (reloadCallId != latestReloadCallId)
150+
return;
151+
152+
IsLoggedIn = isLoggedIn;
153+
}
119154

120155
if (!IsGitHubRepo.Value)
121156
{
122157
//LoadView(UIViewType.NotAGitHubRepo);
123158
return;
124159
}
125160

126-
var connection = await connectionManager.LookupConnection(ActiveRepo);
127-
IsLoggedIn = await connection.IsLoggedIn(hosts);
128-
129161
if (!IsLoggedIn)
130162
{
131163
LoadView(UIViewType.LoggedOut);

0 commit comments

Comments
 (0)