Skip to content

Commit

Permalink
misc perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
soenneker committed Jan 8, 2025
1 parent 5d8940f commit 99338a6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/AsyncSingleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public AsyncSingleton()
_lock = new AsyncLock();
}

public async ValueTask Init(params object[] objects)
public ValueTask Init(params object[] objects)
{
await Init(CancellationToken.None, objects);
return Init(CancellationToken.None, objects);
}

public async ValueTask Init(CancellationToken cancellationToken, params object[] objects)
Expand All @@ -85,7 +85,7 @@ public async ValueTask Init(CancellationToken cancellationToken, params object[]
if (_instance != null)
return;

_instance = await InitInternal(cancellationToken, objects);
_instance = await InitInternal(cancellationToken, objects).NoSync();
}
}

Expand Down Expand Up @@ -263,7 +263,7 @@ public void Dispose()
break;
}

_instance = default;
_instance = null;
GC.SuppressFinalize(this);
}

Expand All @@ -287,7 +287,7 @@ public async ValueTask DisposeAsync()
break;
}

_instance = default;
_instance = null;
GC.SuppressFinalize(this);
}
}
2 changes: 1 addition & 1 deletion src/AsyncSingleton{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public virtual async ValueTask<T> Get(CancellationToken cancellationToken, param
if (_instance != null)
return _instance;

_instance = await GetInternal(cancellationToken, objects);
_instance = await GetInternal(cancellationToken, objects).NoSync();
return _instance;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task DisposeAsync_with_cancellationToken_with_nondisposable_should_
[Fact]
public async Task Async_with_object_and_cancellationToken_should_not_throw()
{
var httpClientSingleton = new AsyncSingleton(async (token, obj) => new object());
var httpClientSingleton = new AsyncSingleton(async (token, _) => new object());

Check warning on line 107 in test/Soenneker.Utils.AsyncSingleton.Tests/AsyncSingletonTests.cs

View workflow job for this annotation

GitHub Actions / publish-package

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

await httpClientSingleton.Init(CancellationToken.None, 3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Soenneker.Tests.Unit" Version="3.0.606" />
<PackageReference Include="xunit.v3" Version="1.0.0" />
<PackageReference Include="xUnit.v3" Version="1.0.0" /></ItemGroup>
<PackageReference Include="xUnit.v3" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Soenneker.Utils.AsyncSingleton.csproj" />
</ItemGroup>

</Project>
</Project>

0 comments on commit 99338a6

Please sign in to comment.