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

net-daemon / netdaemon / 16544531586

26 Jul 2025 10:32PM UTC coverage: 84.131% (+0.04%) from 84.091%
16544531586

Pull #1315

github

web-flow
Merge 98f44e720 into 074af55b8
Pull Request #1315: Minimal NetDaemon

860 of 1147 branches covered (74.98%)

Branch coverage included in aggregate %.

38 of 39 new or added lines in 9 files covered. (97.44%)

4 existing lines in 2 files now uncovered.

3376 of 3888 relevant lines covered (86.83%)

598.28 hits per line

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

85.29
/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 readonly ILogger<BackgroundTaskTracker> _logger = logger;
35✔
8
    private volatile bool _isDisposed;
9

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

12
    public void TrackBackgroundTask(Task? task, string? description = null)
13
    {
14
        ArgumentNullException.ThrowIfNull(task, nameof(task));
31✔
15

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

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

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

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

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

52
        // Using a while look here incase new tasks are added while we are waiting
53
        while (!BackgroundTasks.IsEmpty)
620,318✔
54
        {
55
            var task = await Task.WhenAny( Task.WhenAll(BackgroundTasks.Keys), timeoutTask).ConfigureAwait(false);
620,299✔
56
            if (task == timeoutTask)
620,299✔
57
                break;
58
        }
59
    }
56✔
60
}
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