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

DemoBytom / DemoEngine / 22808717869

07 Mar 2026 10:34PM UTC coverage: 33.499% (+0.4%) from 33.105%
22808717869

push

coveralls.net

DemoBytom
Clean up around the `WorkItem` object pooling

General code cleanup to the `WorkItem` object pooling within `StaThreadService`. Includes registering the pool in DI, as well as resolving it for the service.
Unit tests were updated to test both pooled and non-pooled behavior.

1279 of 3818 relevant lines covered (33.5%)

0.38 hits per line

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

0.0
/src/Demo.Engine.Core/Features/StaThread/StaThreadRegistrationExtensions.cs
1
// Copyright © Michał Dembski and contributors.
2
// Distributed under MIT license. See LICENSE file in the root for more information.
3

4
using System.Threading.Channels;
5
using Microsoft.Extensions.DependencyInjection;
6
using Microsoft.Extensions.DependencyInjection.Extensions;
7
using Microsoft.Extensions.ObjectPool;
8
using WorkItem = Demo.Engine.Core.Features.StaThread.StaThreadService.StaSingleThreadedSynchronizationContext.WorkItem;
9

10
namespace Demo.Engine.Core.Features.StaThread;
11

12
internal static class StaThreadRegistrationExtensions
13
{
14
    public static IServiceCollection AddStaThreadFeature(
15
        this IServiceCollection services)
16
    {
17
        _ = services
×
18
            .AddScoped<IStaThreadService, StaThreadService>()
×
19
            .AddScopedBoundedChannel<StaThreadRequests>(
×
20
                new BoundedChannelOptions(10)
×
21
                {
×
22
                    AllowSynchronousContinuations = false,
×
23
                    FullMode = BoundedChannelFullMode.Wait,
×
24
                    SingleReader = true,
×
25
                    SingleWriter = false,
×
26
                })
×
27
            .AddScoped<IStaThreadWriter, StaThreadWriter>()
×
28
            .AddStaWorkItemObjectPool()
×
29
            ;
×
30

31
        services
×
32
            .TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
×
33
        services
×
34
            .TryAddSingleton(sp
×
35
                =>
×
36
            {
×
37
                var provider = sp.GetRequiredService<ObjectPoolProvider>();
×
38
                var policy = new DefaultPooledObjectPolicy<StaThreadRequests.DoEventsOkRequest>();
×
39

×
40
                var created = provider.Create(policy);
×
41

×
42
                return created;
×
43
            });
×
44

45
        return services;
×
46
    }
47

48
    internal static IServiceCollection AddStaWorkItemObjectPool(
49
        this IServiceCollection services)
50
    {
51
        services
×
52
            .TryAddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
×
53

54
        services
×
55
            .TryAddSingleton(sp
×
56
                =>
×
57
            {
×
58
                var provider = sp.GetRequiredService<ObjectPoolProvider>();
×
59
                var policy = new DefaultPooledObjectPolicy<WorkItem>();
×
60
                var created = provider.Create(policy);
×
61
                return created;
×
62
            });
×
63

64
        return services;
×
65
    }
66
}
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