A:剩余提交

This commit is contained in:
jimmy committed 2025-12-22 16:40:34 +08:00
1 parent dd0681ba90
commit 2c83fc72e4
38 files changed
+3528 -69

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
using System;
using System.Threading.Tasks;
namespace Sharp.EventBus;
internal sealed class EventSubscription : IDisposable
{
public Type EventType { get; }
public int Priority { get; }
public Func<object, Task> Handler { get; }
public Func<object, bool>? Filter { get; }
private readonly Action<EventSubscription> _onDispose;
private bool _disposed;
public EventSubscription(Type eventType, Func<object, Task> handler, Func<object, bool>? filter, int priority, Action<EventSubscription> onDispose)
{
EventType = eventType;
Handler = handler;
Filter = filter;
Priority = priority;
_onDispose = onDispose;
}
public bool CanHandle(object evt)
{
if (evt.GetType() != EventType) return false;
return Filter == null || Filter(evt);
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
_onDispose(this);
}
}