< Summary

Information
Class: Elsa.Workflows.Activities.Parallel
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Parallel.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 50
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
ScheduleChildrenAsync()100%44100%
OnChildCompleted()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Parallel.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.Runtime.CompilerServices;
 3using Elsa.Workflows.Attributes;
 4
 5namespace Elsa.Workflows.Activities;
 6
 7/// <summary>
 8/// Execute a set of activities in parallel.
 9/// </summary>
 10[Activity("Elsa", "Workflows", "Execute a set of activities in parallel.")]
 11[Browsable(false)] // Hidden from the designer until we have Sequential activity designer support.
 12public class Parallel : Container
 13{
 14    private const string ScheduledChildrenProperty = "ScheduledChildren";
 15
 16    /// <inheritdoc />
 1517    public Parallel([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 18    {
 1519    }
 20
 21    /// <inheritdoc />
 1322    public Parallel(params IActivity[] activities) : this()
 23    {
 1324        Activities = activities;
 1325    }
 26
 27    /// <inheritdoc />
 28    protected override async ValueTask ScheduleChildrenAsync(ActivityExecutionContext context)
 29    {
 30        // If there are no activities, complete immediately
 1531        if (Activities.Count == 0)
 32        {
 233            await context.CompleteActivityAsync();
 234            return;
 35        }
 36
 1337        context.SetProperty(ScheduledChildrenProperty, Activities.Count);
 38
 9639        foreach (var activity in Activities)
 3540            await context.ScheduleActivityAsync(activity, OnChildCompleted);
 1541    }
 42
 43    private static async ValueTask OnChildCompleted(ActivityCompletedContext context)
 44    {
 3645        var remainingChildren = context.TargetContext.UpdateProperty<int>(ScheduledChildrenProperty, scheduledChildren =
 46
 1847        if (remainingChildren == 0)
 648            await context.TargetContext.CompleteActivityAsync();
 1849    }
 50}