using System; using System.Threading.Tasks; namespace Sharp.EventBus; internal sealed class EventSubscription : IDisposable { public Type EventType { get; } public int Priority { get; } public Func Handler { get; } public Func? Filter { get; } private readonly Action _onDispose; private bool _disposed; public EventSubscription(Type eventType, Func handler, Func? filter, int priority, Action 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); } }