< Summary - SonghayCore

Information
Class: Songhay.TaskUtility
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/TaskUtility.cs
Line coverage
83%
Covered lines: 15
Uncovered lines: 3
Coverable lines: 18
Total lines: 45
Line coverage: 83.3%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
Delay(...)100%1100%
Delay(...)66.66%675%
Delay(...)100%1100%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/TaskUtility.cs

#LineLine coverage
 1namespace Songhay;
 2
 3/// <summary>
 4/// Members for <see cref="Task"/>.
 5/// </summary>
 6public static class TaskUtility
 7{
 8    /// <summary>
 9    /// Delays with a <see cref="Timer"/> task for the specified <see cref="TimeSpan"/>.
 10    /// </summary>
 11    /// <param name="timeSpan">The specified <see cref="TimeSpan"/>.</param>
 12    /// <param name="actionAfterDelay">The continuation action.</param>
 13    public static Task Delay(TimeSpan timeSpan, Action<Task>? actionAfterDelay) =>
 114        Delay(timeSpan, actionAfterDelay, null);
 15
 16    /// <summary>
 17    /// Delays with a <see cref="Timer"/> task for the specified <see cref="TimeSpan"/>.
 18    /// </summary>
 19    /// <param name="timeSpan">The specified <see cref="TimeSpan"/>.</param>
 20    /// <param name="actionAfterDelay">The continuation action.</param>
 21    /// <param name="schedulerAfterDelay">The work-queue scheduler.</param>
 22    public static Task Delay(TimeSpan timeSpan, Action<Task>? actionAfterDelay,
 23        TaskScheduler? schedulerAfterDelay)
 124    {
 125        var task = Delay(timeSpan);
 26
 127        if (actionAfterDelay != null && schedulerAfterDelay != null)
 028        {
 029            task.ContinueWith(actionAfterDelay, schedulerAfterDelay);
 030        }
 131        else if (actionAfterDelay != null)
 132        {
 133            task.ContinueWith(actionAfterDelay);
 134        }
 35
 136        return task;
 137    }
 38
 39    static Task Delay(TimeSpan timeSpan)
 140    {
 141        var tcs = new TaskCompletionSource<bool>();
 142        new Timer(_ => tcs.SetResult(true)).Change(timeSpan, new TimeSpan(-1));
 143        return tcs.Task;
 144    }
 45}