Skip to content

Commit

Permalink
Update cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel committed Mar 25, 2024
1 parent c044f54 commit fd5df19
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ private async Task SetupBuild(CreateBuildOptions buildOptions)
if (_sharedBuild != null)
{
Build = _sharedBuild;
var copiedApi = _api.Clone();
var buildId = Build.Id;
_sharedBuild.Close = async () =>
{
await copiedApi.FinishBuild(buildId);
copiedApi.Dispose();
};
return;
}

Expand All @@ -117,6 +110,12 @@ private async Task SetupBuild(CreateBuildOptions buildOptions)
{
IsExternal = false
};
var copiedApi = _api.Clone();
Build.Close = async () =>
{
await copiedApi.FinishBuild(Build.Id);
copiedApi.Dispose();
};
_sharedBuild = Build;
}

Expand Down Expand Up @@ -278,11 +277,16 @@ private async Task<string> VisualCheckAsync(string name, VisualCheckOptions opti
/// </summary>
public static async Task Cleanup()
{
if (_sharedBuild?.Close != null)
if (_sharedBuild == null)
{
return;
}

if (_sharedBuild.Close != null)
{
await _sharedBuild.Close();
_sharedBuild = null;
}
_sharedBuild = null;
}

public void Dispose()
Expand Down

0 comments on commit fd5df19

Please sign in to comment.