< 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
 39    public ScheduledTimer(Func<Task> action, Func<TimeSpan> interval)
 10    {
 311        _action = action;
 312        _interval = interval;
 313        _timer = new Timer(Callback, null, interval(), Timeout.InfiniteTimeSpan);
 314    }
 15
 16    private async void Callback(object? state)
 17    {
 218        await _action();
 219        _timer.Change(_interval(), Timeout.InfiniteTimeSpan);
 220    }
 21
 22    public void Dispose()
 23    {
 024        _timer.Dispose();
 025    }
 26
 27    public async ValueTask DisposeAsync()
 28    {
 329        await _timer.DisposeAsync();
 330    }
 31}