< Summary

Information
Class: Elsa.Common.RecurringTasks.ScheduledTimer
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/RecurringTasks/ScheduledTimer.cs
Line coverage
83%
Covered lines: 10
Uncovered lines: 2
Coverable lines: 12
Total lines: 31
Line coverage: 83.3%
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
.ctor(...)100%11100%
Callback()100%11100%
Dispose()100%210%
DisposeAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/RecurringTasks/ScheduledTimer.cs

#LineLine coverage
 1namespace Elsa.Common.RecurringTasks;
 2
 3public class ScheduledTimer : IDisposable, IAsyncDisposable
 4{
 5    private readonly Func<Task> _action;
 6    private readonly Func<TimeSpan> _interval;
 7    private readonly Timer _timer;
 8
 219    public ScheduledTimer(Func<Task> action, Func<TimeSpan> interval)
 10    {
 2111        _action = action;
 2112        _interval = interval;
 2113        _timer = new Timer(Callback, null, interval(), Timeout.InfiniteTimeSpan);
 2114    }
 15
 16    private async void Callback(object? state)
 17    {
 1618        await _action();
 1619        _timer.Change(_interval(), Timeout.InfiniteTimeSpan);
 1620    }
 21
 22    public void Dispose()
 23    {
 024        _timer.Dispose();
 025    }
 26
 27    public async ValueTask DisposeAsync()
 28    {
 929        await _timer.DisposeAsync();
 930    }
 31}