Class EventSubscription
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Abstractions.dll
Represents a subscription to an event that can be unsubscribed by disposing.
public sealed class EventSubscription : IDisposable
- Inheritance
-
EventSubscription
- Implements
- Inherited Members
Examples
// Subscribe to an event
var subscription = world.OnEntityCreated((entity, name) =>
{
Console.WriteLine($"Entity created: {entity}");
});
// Later, unsubscribe by disposing
subscription.Dispose();
Remarks
Event subscriptions are returned by event registration methods and implement IDisposable to allow clean unsubscription. Disposing a subscription removes the handler from the event source.
Subscriptions are idempotent: disposing the same subscription multiple times has no additional effect after the first disposal.
This class is thread-safe: concurrent calls to Dispose() from multiple threads are handled correctly, with only the first call executing the unsubscribe action.
Constructors
EventSubscription(Action)
Represents a subscription to an event that can be unsubscribed by disposing.
public EventSubscription(Action unsubscribe)
Parameters
unsubscribeActionThe action to execute when disposing this subscription.
Examples
// Subscribe to an event
var subscription = world.OnEntityCreated((entity, name) =>
{
Console.WriteLine($"Entity created: {entity}");
});
// Later, unsubscribe by disposing
subscription.Dispose();
Remarks
Event subscriptions are returned by event registration methods and implement IDisposable to allow clean unsubscription. Disposing a subscription removes the handler from the event source.
Subscriptions are idempotent: disposing the same subscription multiple times has no additional effect after the first disposal.
This class is thread-safe: concurrent calls to Dispose() from multiple threads are handled correctly, with only the first call executing the unsubscribe action.
Methods
Dispose()
Unsubscribes from the event by removing the handler.
public void Dispose()
Remarks
This method is idempotent: calling it multiple times has no additional effect after the first call. This method is thread-safe.