1234567891011121314151617181920212223242526 |
- using Microsoft.Extensions.DependencyInjection;
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- namespace FastGithub.Scanner.Middlewares
- {
- [Service(ServiceLifetime.Singleton)]
- sealed class ConcurrentMiddleware : IGithubScanMiddleware
- {
- private readonly SemaphoreSlim semaphoreSlim = new(Environment.ProcessorCount * 4);
- public async Task InvokeAsync(GithubContext context, Func<Task> next)
- {
- try
- {
- await this.semaphoreSlim.WaitAsync();
- await next();
- }
- finally
- {
- this.semaphoreSlim.Release();
- }
- }
- }
- }
|