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

connorivy / beamOS / 14882999397

07 May 2025 12:10PM UTC coverage: 70.971%. First build
14882999397

Pull #85

github

web-flow
Merge 16abd45d8 into e6bb4b15c
Pull Request #85: Add load combos

867 of 1830 branches covered (47.38%)

Branch coverage included in aggregate %.

1474 of 1639 new or added lines in 74 files covered. (89.93%)

7536 of 10010 relevant lines covered (75.28%)

0.78 hits per line

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

32.76
/src/StructuralAnalysis/BeamOs.StructuralAnalysis.Sdk/GuidLockManager.cs
1
using System;
2
using System.Collections.Concurrent;
3
using System.Threading;
4
using System.Threading.Tasks;
5

6
namespace BeamOs.StructuralAnalysis.Sdk;
7

8
public class AsyncGuidLockManager : IDisposable
9
{
10
    private readonly ConcurrentDictionary<Guid, SemaphoreSlim> _semaphores = new();
2✔
11

12
    private readonly Lock _lock = new Lock();
2✔
13

14
    // Gets or creates a SemaphoreSlim for the specified GUID
15
    private SemaphoreSlim GetSemaphore(Guid id)
16
    {
2✔
17
        lock (_lock)
18
        {
2✔
19
            return _semaphores.GetOrAdd(id, _ => new SemaphoreSlim(1, 1));
2✔
20
        }
21
    }
2✔
22

23
    // Executes async code with a GUID-specific lock
24
    public async Task<T> ExecuteWithLockAsync<T>(Guid id, Func<Task<T>> taskFactory)
25
    {
2✔
26
        var semaphore = GetSemaphore(id);
2✔
27
        await semaphore.WaitAsync().ConfigureAwait(false);
2✔
28

29
        try
30
        {
2✔
31
            return await taskFactory().ConfigureAwait(false);
2✔
32
        }
33
        finally
34
        {
2✔
35
            semaphore.Release();
2✔
36
        }
2✔
37
    }
2✔
38

39
    // Executes async action with a GUID-specific lock
40
    public async Task ExecuteWithLockAsync(Guid id, Func<Task> task)
NEW
41
    {
×
NEW
42
        var semaphore = GetSemaphore(id);
×
NEW
43
        await semaphore.WaitAsync().ConfigureAwait(false);
×
44

45
        try
NEW
46
        {
×
NEW
47
            await task().ConfigureAwait(false);
×
NEW
48
        }
×
49
        finally
NEW
50
        {
×
NEW
51
            semaphore.Release();
×
NEW
52
        }
×
NEW
53
    }
×
54

55
    // Cleanup unused semaphores to prevent memory leaks
56
    public void CleanupUnusedSemaphores()
NEW
57
    {
×
NEW
58
        foreach (var pair in _semaphores)
×
NEW
59
        {
×
60
            // Remove semaphore if no one is waiting and current count is 1 (available)
NEW
61
            if (pair.Value.CurrentCount == 1)
×
NEW
62
            {
×
NEW
63
                _semaphores.TryRemove(pair.Key, out _);
×
NEW
64
                pair.Value.Dispose();
×
NEW
65
            }
×
NEW
66
        }
×
NEW
67
    }
×
68

69
    public void Dispose()
NEW
70
    {
×
NEW
71
        foreach (var semaphore in _semaphores.Values)
×
NEW
72
        {
×
NEW
73
            semaphore.Dispose();
×
NEW
74
        }
×
NEW
75
        _semaphores.Clear();
×
NEW
76
    }
×
77
}
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