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

Commit 79d4d7d

Browse files
committed
Ensure the PR session manager is initialized.
1 parent ffd5072 commit 79d4d7d

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/GitHub.Exports.Reactive/Services/IPullRequestSessionManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public interface IPullRequestSessionManager : INotifyPropertyChanged
3131
/// </returns>
3232
IPullRequestSession CurrentSession { get; }
3333

34+
/// <summary>
35+
/// Ensures that the service is initialized.
36+
/// </summary>
37+
/// <returns>A task that when completed indicates that the service is initialized.</returns>
38+
/// <remarks>
39+
/// If you are simplying monitoring changes to the <see cref="CurrentSession"/> then you
40+
/// don't need to call this method: <see cref="CurrentSession"/> will be updated on
41+
/// initialization. If however, you want to be sure that <see cref="CurrentSession"/> is
42+
/// initialized, you can await the task returned from this method.
43+
/// </remarks>
44+
Task EnsureInitialized();
45+
3446
/// <summary>
3547
/// Gets an <see cref="IPullRequestSessionFile"/> that tracks the live state of a document.
3648
/// </summary>

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class PullRequestSessionManager : ReactiveObject, IPullRequestSessionMana
3636
readonly IModelServiceFactory modelServiceFactory;
3737
readonly Dictionary<Tuple<string, int>, WeakReference<PullRequestSession>> sessions =
3838
new Dictionary<Tuple<string, int>, WeakReference<PullRequestSession>>();
39+
TaskCompletionSource<object> initialized;
3940
IPullRequestSession currentSession;
4041
ILocalRepositoryModel repository;
4142

@@ -65,6 +66,7 @@ public PullRequestSessionManager(
6566
this.sessionService = sessionService;
6667
this.connectionManager = connectionManager;
6768
this.modelServiceFactory = modelServiceFactory;
69+
initialized = new TaskCompletionSource<object>(null);
6870

6971
Observable.FromEventPattern(teamExplorerContext, nameof(teamExplorerContext.StatusChanged))
7072
.ObserveOn(RxApp.MainThreadScheduler)
@@ -82,6 +84,10 @@ public IPullRequestSession CurrentSession
8284
private set { this.RaiseAndSetIfChanged(ref currentSession, value); }
8385
}
8486

87+
/// <inheritdoc/>
88+
public Task EnsureInitialized() => initialized.Task;
89+
90+
/// <inheritdoc/>
8591
public async Task<IPullRequestSessionFile> GetLiveFile(
8692
string relativePath,
8793
ITextView textView,
@@ -230,6 +236,7 @@ async Task StatusChanged()
230236
}
231237

232238
CurrentSession = session;
239+
initialized.SetResult(null);
233240
}
234241
catch (Exception e)
235242
{

src/GitHub.VisualStudio/Menus/ShowCurrentPullRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public async void Activate(object data = null)
2626
try
2727
{
2828
var pullRequestSessionManager = ServiceProvider.ExportProvider.GetExportedValueOrDefault<IPullRequestSessionManager>();
29+
await pullRequestSessionManager.EnsureInitialized();
30+
2931
var session = pullRequestSessionManager?.CurrentSession;
3032
if (session == null)
3133
{

0 commit comments

Comments
 (0)