WIP #738 - Further refactor (remove loop)
This is pretty trivial really, it just cuts down on indentation and moves the looping into a Linq map (Select) which builds a collection and then reduces it (SelectMany) to a flattened collection. Also remove some needless await'ing.
This commit is contained in:
parent
d9724e5267
commit
f00f02041a
|
|
@ -45,11 +45,11 @@ namespace Elsa.Triggers
|
|||
.ToListAsync(cancellationToken);
|
||||
|
||||
var tasksOfListsOfTriggers = supportedBookmarkProviders
|
||||
.Select(async bookmarkProvider => await GetTriggersForBookmarkProvider(bookmarkProvider,
|
||||
bookmarkProviderContext,
|
||||
activityBlueprint,
|
||||
workflowExecutionContext.WorkflowBlueprint,
|
||||
cancellationToken));
|
||||
.Select(bookmarkProvider => GetTriggersForBookmarkProvider(bookmarkProvider,
|
||||
bookmarkProviderContext,
|
||||
activityBlueprint,
|
||||
workflowExecutionContext.WorkflowBlueprint,
|
||||
cancellationToken));
|
||||
return (await Task.WhenAll(tasksOfListsOfTriggers))
|
||||
.SelectMany(x => x)
|
||||
.ToList();
|
||||
|
|
|
|||
|
|
@ -37,26 +37,32 @@ namespace Elsa.Triggers
|
|||
public async Task<IEnumerable<WorkflowTrigger>> GetTriggersAsync(IEnumerable<IWorkflowBlueprint> workflowBlueprints,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var allTriggers = new List<WorkflowTrigger>();
|
||||
var activityTypes = (await activityTypeService.GetActivityTypesAsync(cancellationToken)).ToDictionary(x => x.TypeName);
|
||||
var activityTypes = (await activityTypeService.GetActivityTypesAsync(cancellationToken))
|
||||
.ToDictionary(x => x.TypeName);
|
||||
|
||||
foreach (var workflowBlueprint in workflowBlueprints)
|
||||
{
|
||||
var startingActivityBlueprints = workflowBlueprint.GetStartActivities();
|
||||
var workflowExecutionContext = await workflowExecutionContextFactory.CreateWorkflowExecutionContextAsync(workflowBlueprint,
|
||||
cancellationToken);
|
||||
var tasksOfCollectionsOfTriggers = startingActivityBlueprints
|
||||
.Select(async activityBlueprint => await triggerProvider.GetTriggersForActivityBlueprintAsync(activityBlueprint,
|
||||
workflowExecutionContext,
|
||||
activityTypes,
|
||||
cancellationToken));
|
||||
var triggers = (await Task.WhenAll(tasksOfCollectionsOfTriggers))
|
||||
.SelectMany(x => x)
|
||||
.ToList();
|
||||
allTriggers.AddRange(triggers);
|
||||
}
|
||||
var tasksOfListsOfTriggers = workflowBlueprints
|
||||
.Select(workflowBlueprint => GetWorkflowTriggersForWorkflowBlueprintAsync(workflowBlueprint, activityTypes, cancellationToken));
|
||||
|
||||
return (await Task.WhenAll(tasksOfListsOfTriggers))
|
||||
.SelectMany(x => x)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return allTriggers;
|
||||
async Task<IList<WorkflowTrigger>> GetWorkflowTriggersForWorkflowBlueprintAsync(IWorkflowBlueprint workflowBlueprint,
|
||||
IDictionary<string, ActivityType> activityTypes,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var startingActivityBlueprints = workflowBlueprint.GetStartActivities();
|
||||
var workflowExecutionContext = await workflowExecutionContextFactory.CreateWorkflowExecutionContextAsync(workflowBlueprint,
|
||||
cancellationToken);
|
||||
var tasksOfCollectionsOfTriggers = startingActivityBlueprints
|
||||
.Select(async activityBlueprint => await triggerProvider.GetTriggersForActivityBlueprintAsync(activityBlueprint,
|
||||
workflowExecutionContext,
|
||||
activityTypes,
|
||||
cancellationToken));
|
||||
return (await Task.WhenAll(tasksOfCollectionsOfTriggers))
|
||||
.SelectMany(x => x)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue