feat(eventbus): add platform runtimes and benchmarks

Add the Entities NativeQueue adapter, standalone .NET runtime and source generator, reproducible smoke coverage, and Unity benchmark assets for EventBus 2.0.
This commit is contained in:
2026-08-26 01:17:39 +08:00
parent ad5a7b68a3
commit 724e0bc8d8
32 changed files with 1813 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using ShrinkEventBus;
internal readonly struct PingEvent : IShrinkEvent
{
public PingEvent(int value) => Value = value;
public int Value { get; }
}
[ShrinkEventSubscriber]
internal sealed partial class SmokeSubscriber
{
public int Sum { get; private set; }
public int ThreadId { get; private set; }
[ShrinkSubscribe]
private void OnPing(PingEvent evt)
{
Sum += evt.Value;
ThreadId = Thread.CurrentThread.ManagedThreadId;
}
}
[ShrinkEventSubscriber(DefaultBus = "game")]
internal static partial class StaticSmokeSubscriber
{
public static int Sum { get; set; }
[ShrinkSubscribe]
private static void OnPing(PingEvent evt) => Sum += evt.Value;
}
internal static class Program
{
private static async Task<int> Main()
{
using var host = new ShrinkEventBusHost();
var game = host.CreateBus(ShrinkBusKey.Game, ShrinkBusOptions.Inline());
var workerKey = new ShrinkBusKey("worker", "smoke");
var worker = host.CreateBus(workerKey, ShrinkBusOptions.DedicatedThread());
var gameSubscriber = new SmokeSubscriber();
var workerSubscriber = new SmokeSubscriber();
var callerThread = Thread.CurrentThread.ManagedThreadId;
using var gameBinding = host.Attach(gameSubscriber, ShrinkBusKey.Game);
using var workerBinding = host.Attach(workerSubscriber, workerKey);
game.Post(new PingEvent(2));
await worker.PostAsync(new PingEvent(3));
if (gameSubscriber.Sum != 2 || workerSubscriber.Sum != 3 || StaticSmokeSubscriber.Sum != 2 ||
workerSubscriber.ThreadId == callerThread)
{
Console.Error.WriteLine("FAIL");
return 1;
}
Console.WriteLine("PASS");
return 0;
}
}