NDelegate is more performant replacement for Action. Whenever new delegate is added or removed from an Action field, the delegate list it contains is actually completely recreated since it is immutable. NDelegate thus reduces the garbage created on subscribe/unsubscribe operations by maintaining a single modifiable list of delegates.
Other benefits include:
- Exception isolation so that Exception in one handler doesn't prevent other handlers from being called.
- Recursive dispatch detection
- Multiple action type support on
NDelegate<T>
- Support for auto unsubscribe
It also has NDelegate<T>
version which is an equivalent of an Action<T>
with a single parameter but also supports
subscribing of Action
without parameter and also Action<T, T>
which is useful for change data events.
NDelegateUnsubscriber.Create(nDelegate, action)
returns IDisposable that will unsubscribe the given action
from the
given nDelegate
in its Dispose
method.