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

Commit 5f502af

Browse files
Merge pull request #1999 from github/refactor/tidy-up-Rx-PullRequestStatusBarManager
Tidy up Rx in PullRequestStatusBarManager
2 parents e8fd7e7 + 6df00c6 commit 5f502af

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public class PullRequestStatusBarManager
3737
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
3838
readonly Lazy<IConnectionManager> connectionManager;
3939

40-
IDisposable currentSessionSubscription;
41-
4240
[ImportingConstructor]
4341
public PullRequestStatusBarManager(
4442
Lazy<IUsageTracker> usageTracker,
@@ -68,41 +66,31 @@ public void StartShowingStatus()
6866
{
6967
try
7068
{
71-
teamExplorerContext.Value.WhenAnyValue(x => x.ActiveRepository)
69+
var activeReposities = teamExplorerContext.Value.WhenAnyValue(x => x.ActiveRepository);
70+
var sessions = pullRequestSessionManager.Value.WhenAnyValue(x => x.CurrentSession);
71+
activeReposities
72+
.CombineLatest(sessions, (r, s) => (r, s))
73+
.Throttle(TimeSpan.FromSeconds(1))
7274
.ObserveOn(RxApp.MainThreadScheduler)
73-
.Subscribe(x => RefreshActiveRepository(x));
75+
.Subscribe(x => RefreshCurrentSession(x.r, x.s).Forget(log));
7476
}
7577
catch (Exception e)
7678
{
7779
log.Error(e, "Error initializing");
7880
}
7981
}
8082

81-
void RefreshActiveRepository(ILocalRepositoryModel repository)
82-
{
83-
currentSessionSubscription?.Dispose();
84-
currentSessionSubscription = pullRequestSessionManager.Value.WhenAnyValue(x => x.CurrentSession)
85-
.Subscribe(x => RefreshCurrentSession(repository, x).Forget());
86-
}
87-
8883
async Task RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
8984
{
90-
try
91-
{
92-
var showStatus = await IsDotComOrEnterpriseRepository(repository);
93-
if (!showStatus)
94-
{
95-
ShowStatus(null);
96-
return;
97-
}
98-
99-
var viewModel = CreatePullRequestStatusViewModel(session);
100-
ShowStatus(viewModel);
101-
}
102-
catch (Exception e)
85+
var showStatus = await IsDotComOrEnterpriseRepository(repository);
86+
if (!showStatus)
10387
{
104-
log.Error(e, nameof(RefreshCurrentSession));
88+
ShowStatus(null);
89+
return;
10590
}
91+
92+
var viewModel = CreatePullRequestStatusViewModel(session);
93+
ShowStatus(viewModel);
10694
}
10795

10896
async Task<bool> IsDotComOrEnterpriseRepository(ILocalRepositoryModel repository)

0 commit comments

Comments
 (0)