using Elsa.Workflows.Runtime.Services; namespace Elsa.Workflows.Runtime.Implementations; public class StimulusInterpreter : IStimulusInterpreter { private readonly IEnumerable _workflowExecutionInstructionProviders; public StimulusInterpreter(IEnumerable workflowExecutionInstructionProviders) { _workflowExecutionInstructionProviders = workflowExecutionInstructionProviders; } public async Task> GetExecutionInstructionsAsync(IStimulus stimulus, CancellationToken cancellationToken = default) { var providers = _workflowExecutionInstructionProviders.Where(x => x.GetSupportsStimulus(stimulus)).ToList(); var tasks = providers.Select(x => x.GetInstructionsAsync(stimulus, cancellationToken).AsTask()); return (await Task.WhenAll(tasks)).SelectMany(x => x); } }