Skip to content

Commit

Permalink
Prevent disposal during WriteAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Mar 9, 2023
1 parent 72a8082 commit 259709b
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,28 +538,34 @@ private static IComparable GetConfiguredProjectVersion(IProjectValueVersions upd
return update.DataSourceVersions[ProjectDataSources.ConfiguredProjectVersion];
}

public async Task WriteAsync(Func<IWorkspace, Task> action, CancellationToken cancellationToken)
public Task WriteAsync(Func<IWorkspace, Task> action, CancellationToken cancellationToken)
{
Requires.NotNull(action);
Verify.NotDisposed(this);

cancellationToken = CancellationTokenExtensions.CombineWith(_unloadCancellationToken, cancellationToken).Token;

await WhenContextCreated(cancellationToken);
return ExecuteUnderLockAsync(async _ =>
{
await WhenContextCreated(cancellationToken);
await ExecuteUnderLockAsync(_ => action(this), cancellationToken);
await action(this);
},
cancellationToken);
}

public async Task<T> WriteAsync<T>(Func<IWorkspace, Task<T>> action, CancellationToken cancellationToken)
public Task<T> WriteAsync<T>(Func<IWorkspace, Task<T>> action, CancellationToken cancellationToken)
{
Requires.NotNull(action);
Verify.NotDisposed(this);

cancellationToken = CancellationTokenExtensions.CombineWith(_unloadCancellationToken, cancellationToken).Token;

await WhenContextCreated(cancellationToken);
return ExecuteUnderLockAsync(async _ =>
{
await WhenContextCreated(cancellationToken);
return await ExecuteUnderLockAsync(_ => action(this), cancellationToken);
return await action(this);
},
cancellationToken);
}

private async Task WhenContextCreated(CancellationToken cancellationToken)
Expand Down

0 comments on commit 259709b

Please sign in to comment.