• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 17580595161

09 Sep 2025 11:06AM UTC coverage: 84.073% (+0.1%) from 83.971%
17580595161

Pull #1315

github

web-flow
Merge 2428f31f0 into abec1da85
Pull Request #1315: Minimal NetDaemon

862 of 1147 branches covered (75.15%)

Branch coverage included in aggregate %.

47 of 48 new or added lines in 10 files covered. (97.92%)

1 existing line in 1 file now uncovered.

3382 of 3901 relevant lines covered (86.7%)

120.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.86
/src/HassModel/NetDaemon.HassModel/Internal/BackgroundTaskTracker.cs
1
using System.Collections.Concurrent;
2

3
namespace NetDaemon.HassModel.Internal;
4

5
internal class BackgroundTaskTracker(ILogger<BackgroundTaskTracker> logger) : IBackgroundTaskTracker
35✔
6
{
7
    private volatile bool _isDisposed;
8

9
    internal readonly ConcurrentDictionary<Task, object?> BackgroundTasks = new();
35✔
10

11
    public void TrackBackgroundTask(Task? task, string? description = null)
12
    {
13
        if (task == null) return;
31!
14

15
        BackgroundTasks.TryAdd(task, null);
31✔
16

17
        [SuppressMessage("", "CA1031")]
18
        async Task Wrap()
19
        {
20
            try
21
            {
22
                await task.ConfigureAwait(false);
31✔
23
            }
30✔
24
            catch (OperationCanceledException)
×
25
            {
NEW
26
                logger.LogTrace("Task was canceled processing Home Assistant event: {Description}", description ?? "");
×
27
            }
×
28
            catch (Exception e)
1✔
29
            {
30
                logger.LogError(e, "Exception processing Home Assistant event: {Description}", description ?? "");
1✔
31
            }
1✔
32
            finally
33
            {
34
                BackgroundTasks.TryRemove(task, out var _);
31✔
35
            }
36
        }
31✔
37

38
        // We do not handle task here cause exceptions
39
        // are handled in the Wrap local functions and
40
        // all tasks should be cancelable
41
        _ = Wrap();
31✔
42
    }
31✔
43

44
    public async ValueTask DisposeAsync()
45
    {
46
        if (_isDisposed) return;
92✔
47
        _isDisposed = true;
20✔
48

49
        var timeoutTask = Task.Delay(TimeSpan.FromSeconds(5));
20✔
50

51
        // Using a while look here incase new tasks are added while we are waiting
52
        while (!BackgroundTasks.IsEmpty)
1,423✔
53
        {
54
            var task = await Task.WhenAny( Task.WhenAll(BackgroundTasks.Keys), timeoutTask).ConfigureAwait(false);
1,404✔
55
            if (task == timeoutTask)
1,404✔
56
                break;
57
        }
58
    }
56✔
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc