Use IAsyncDisposable instead of AsyncLazy<T> for lazy cancellation of final OOP request#61020
Use IAsyncDisposable instead of AsyncLazy<T> for lazy cancellation of final OOP request#61020sharwell merged 3 commits intodotnet:mainfrom
Conversation
… final OOP request
| _remoteWorkspace._solutionChecksumToLazySolution.Remove(_solutionChecksum); | ||
| } | ||
|
|
||
| await _task.NoThrowAwaitable(false); |
There was a problem hiding this comment.
📝 This line is the key change (AsyncLazy<T> does not await the inner task following its final cancellation)
| if (fromPrimaryBranch) | ||
| (newSolution, _) = await this.TryUpdateWorkspaceCurrentSolutionAsync(workspaceVersion, newSolution, cancellationToken).ConfigureAwait(false); | ||
| // Actually get the solution, computing it ourselves, or getting the result that another caller was computing. | ||
| var newSolution = await refCountedLazySolution.Target.Task.WithCancellation(cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
ok. would def like a walk through here. this allows teh caller to cancel asap. and then the idea is that the disposable will ensure we dispose the lazy solution (Afaict). however, it's unclear what actually ensures the lazy solution ends up finishing computation and doesn't continue running even once all the callers have returned back out.
| _remoteWorkspace._solutionChecksumToLazySolution.Remove(_solutionChecksum); | ||
| } | ||
|
|
||
| await _task.NoThrowAwaitable(false); |
There was a problem hiding this comment.
ah, i think i got it. this is the critical line it seems. the last one who actually does the dispose will wait on the task being complete. i think this needs doc.s
There was a problem hiding this comment.
plz doc why NoThrowAwaitable.
| } | ||
| } | ||
|
|
||
| private sealed class LazySolution : IAsyncDisposable, IDisposable |
There was a problem hiding this comment.
this seems like a generally useful pattern. perhaps could elevate to a common location?
|
Thanks for this. Very clean and clear solution! |
No description provided.