Skip to content

Commit

Permalink
slightly cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
kosak committed Sep 2, 2024
1 parent d185285 commit 4fe7902
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions csharp/ExcelAddIn/providers/SessionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,16 @@ void CreateSessionBaseInSeparateThread(CredentialsBase credentials) {
result = StatusOr<SessionBase>.OfStatus(ex.Message);
}

// By the time we get here, some time has passed. Decide whether to keep it.
// By the time we get here, some time has passed. Have our results become moot?
if (!ReferenceEquals(localLatestCookie, _sharedSetCredentialsCookie.Value)) {
// No, it's stale. Dispose the SessionBase if we have it.
_ = result.AcceptVisitor(sb => {
sb.Dispose();
return Unit.Instance;
},
_ => Unit.Instance
);
// Our results are moot. Dispose of them.
if (result.GetValueOrStatus(out var sb, out _)) {
sb.Dispose();
}
return;
}

// Keep it and tell everyone about it (on the worker thread).
// Our results are valid. Keep them and tell everyone about it (on the worker thread).
workerThread.Invoke(() => _sessionObservers.SetAndSend(ref _session, result));
}

Expand Down

0 comments on commit 4fe7902

Please sign in to comment.