public async ValueTask <IRequestExecutor> GetRequestExecutorNoLockAsync( NameString schemaName = default, CancellationToken cancellationToken = default) { schemaName = schemaName.HasValue ? schemaName : Schema.DefaultName; if (!_executors.TryGetValue(schemaName, out RegisteredExecutor? re)) { IServiceProvider schemaServices = await CreateSchemaServicesAsync(schemaName, cancellationToken) .ConfigureAwait(false); re = new RegisteredExecutor ( schemaServices.GetRequiredService <IRequestExecutor>(), schemaServices, schemaServices.GetRequiredService <IDiagnosticEvents>() ); re.DiagnosticEvents.ExecutorCreated(schemaName, re.Executor); _executors.TryAdd(schemaName, re); } return(re.Executor); }
private void BeginRunEvictionEvents(RegisteredExecutor registeredExecutor) { Task.Run(async() => { foreach (OnRequestExecutorEvictedAction action in registeredExecutor.FactoryOptions.OnRequestExecutorEvicted) { action.Action?.Invoke(registeredExecutor.Executor); if (action.AsyncAction is not null) { await action.AsyncAction.Invoke( registeredExecutor.Executor, CancellationToken.None) .ConfigureAwait(false); } } }); }
public async ValueTask <IRequestExecutor> GetRequestExecutorNoLockAsync( NameString schemaName = default, CancellationToken cancellationToken = default) { schemaName = schemaName.HasValue ? schemaName : Schema.DefaultName; if (!_executors.TryGetValue(schemaName, out RegisteredExecutor? re)) { RequestExecutorFactoryOptions options = await _optionsMonitor.GetAsync(schemaName, cancellationToken) .ConfigureAwait(false); IServiceProvider schemaServices = await CreateSchemaServicesAsync(schemaName, options, cancellationToken) .ConfigureAwait(false); re = new RegisteredExecutor ( schemaServices.GetRequiredService <IRequestExecutor>(), schemaServices, schemaServices.GetRequiredService <IDiagnosticEvents>(), options ); foreach (OnRequestExecutorCreatedAction action in options.OnRequestExecutorCreated) { action.Action?.Invoke(re.Executor); if (action.AsyncAction is not null) { await action.AsyncAction.Invoke(re.Executor, cancellationToken) .ConfigureAwait(false); } } re.DiagnosticEvents.ExecutorCreated(schemaName, re.Executor); _executors.TryAdd(schemaName, re); } return(re.Executor); }