< Summary

Information
Class: Elsa.Workflows.Runtime.DeferredTasksExecutionContextExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/DeferredTasksExecutionContextExtensions.cs
Line coverage
64%
Covered lines: 11
Uncovered lines: 6
Coverable lines: 17
Total lines: 58
Line coverage: 64.7%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
DeferTask(...)100%11100%
DeferTask(...)100%210%
DeferTask(...)100%11100%
ExecuteDeferredTasksAsync()100%11100%
GetDeferredTasksInternal(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/DeferredTasksExecutionContextExtensions.cs

#LineLine coverage
 1using Elsa.Extensions;
 2
 3namespace Elsa.Workflows.Runtime;
 4
 5/// <summary>
 6/// Provides a set of extension methods for working with deferred tasks within a workflow execution context.
 7/// </summary>
 8public static class DeferredTasksExecutionContextExtensions
 9{
 310    private static readonly object DeferredTasksKey = new();
 11
 12    /// <summary>
 13    /// Defers the execution of a task within the workflow execution context.
 14    /// Deferred tasks are executed right after bookmarks have been persisted.
 15    /// </summary>
 16    public static void DeferTask(this WorkflowExecutionContext context, Func<Task> task)
 17    {
 318        var deferredTasks = context.GetDeferredTasksInternal();
 319        deferredTasks.Add(task);
 320    }
 21
 22    /// <summary>
 23    /// Defers the execution of a task within the workflow execution context.
 24    /// Deferred tasks are executed right after bookmarks have been persisted.
 25    /// </summary>
 26    public static void DeferTask(this ActivityExecutionContext context, Action task)
 27    {
 028        context.DeferTask(() =>
 029        {
 030            task();
 031            return Task.CompletedTask;
 032        });
 033    }
 34
 35    /// <summary>
 36    /// Defers the execution of a task within the workflow execution context.
 37    /// Deferred tasks are executed right after bookmarks have been persisted.
 38    /// </summary>
 39    public static void DeferTask(this ActivityExecutionContext context, Func<Task> task)
 40    {
 341        context.WorkflowExecutionContext.DeferTask(task);
 342    }
 43
 44    /// <summary>
 45    /// Executes all deferred tasks within the workflow execution context.
 46    /// </summary>
 47    public static async Task ExecuteDeferredTasksAsync(this WorkflowExecutionContext context)
 48    {
 46649        var deferredTasks = context.GetDeferredTasksInternal();
 46950        var tasks = deferredTasks.Select(x => x()).ToList();
 46651        await Task.WhenAll(tasks);
 46652    }
 53
 54    private static ICollection<Func<Task>> GetDeferredTasksInternal(this WorkflowExecutionContext context)
 55    {
 93556        return context.TransientProperties.GetOrAdd(DeferredTasksKey, () => new List<Func<Task>>());
 57    }
 58}