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

Commit 09d477f

Browse files
committed
Use CombineLatest not multiple subscriptions
1 parent e8fd7e7 commit 09d477f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 5 additions & 11 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,23 +66,19 @@ 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))
7273
.ObserveOn(RxApp.MainThreadScheduler)
73-
.Subscribe(x => RefreshActiveRepository(x));
74+
.Subscribe(x => RefreshCurrentSession(x.r, x.s).Forget());
7475
}
7576
catch (Exception e)
7677
{
7778
log.Error(e, "Error initializing");
7879
}
7980
}
8081

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-
8882
async Task RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
8983
{
9084
try

0 commit comments

Comments
 (0)