Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ In the context of Blazor components, this functionality is particularly valuable
- **Automatic Cleanup:** Dead subscribers (whose targets have been garbage-collected) are automatically removed when the event is raised.
- **Simple API:** Intuitive methods for subscribing, unsubscribing, and publishing events.

### Publication behavior

- Subscribers are invoked sequentially in subscription order.
- Publishing uses a subscriber snapshot taken when publication starts. Subscribing or unsubscribing during publication affects later publications, not the current one.
- Cancellation is observed before each subscriber is invoked. Cancellation-aware subscribers receive the token passed to `PublishAsync`.
- Static handlers remain alive for the lifetime of the event source. Instance handlers, including capturing lambdas, are held weakly and do not need explicit unsubscription to become collectible.
- Exceptions from synchronous handlers propagate as their original exception type. Exceptions from asynchronous handlers are propagated after the returned task is awaited.
- Multicast delegates subscribe each invocation independently and can be unsubscribed as a group.

## Installation

Install the latest stable package via NuGet:
Expand Down Expand Up @@ -82,11 +91,11 @@ public record MyEventData(string Message);
* `Subscribe(Action handler)`\
`Subscribe(Func<Task> handler)`\
`Subscribe(Func<CancellationToken, Task> handler)`\
Subscribes the specified handler to the event. The handler will be invoked when the event is raised, provided that its target is still alive.
Subscribes the specified handler to the event. A multicast delegate subscribes each invocation. The handlers will be invoked when the event is raised, provided that their targets are still alive.
* `Unsubscribe(Action handler)`\
`Unsubscribe(Func<Task> handler)`\
`Unsubscribe(Func<CancellationToken, Task> handler)`\
Unsubscribes the specified handler from the event.
Unsubscribes the specified handler from the event. A multicast delegate unsubscribes all matching invocations.
* `PublishAsync(CancellationToken cancellationToken = default)`\
Raises the event by invoking all live subscribers. Dead subscribers (whose targets have been garbage-collected) are removed.

Expand All @@ -96,11 +105,11 @@ public record MyEventData(string Message);
* `Subscribe(Action<TEvent> handler)`\
`Subscribe(Func<TEvent, Task> handler)`\
`Subscribe(Func<TEvent, CancellationToken, Task> handler)`\
Subscribes the specified handler to the event. The handler will be invoked when the event is raised, provided that its target is still alive.
Subscribes the specified handler to the event. A multicast delegate subscribes each invocation. The handlers will be invoked when the event is raised, provided that their targets are still alive.
* `Unsubscribe(Action<TEvent> handler)`\
`Unsubscribe(Func<TEvent, Task> handler)`\
`Unsubscribe(Func<TEvent, CancellationToken, Task> handler)`\
Unsubscribes the specified handler from the event.
Unsubscribes the specified handler from the event. A multicast delegate unsubscribes all matching invocations.
* `PublishAsync(TEvent eventData, CancellationToken cancellationToken = default)`\
Raises the event by invoking all live subscribers with the provided event data. Dead subscribers (whose targets have been garbage-collected) are removed.

Expand Down
17 changes: 13 additions & 4 deletions src/WeakEvent/PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ WeakEvent is a lightweight .NET library that implements the weak event pattern u
- **Automatic Cleanup:** Dead subscribers are removed automatically during event publishing.
- **Simple API:** Intuitive methods for subscribing, unsubscribing, and publishing events.

## Publication behavior

- Subscribers are invoked sequentially in subscription order.
- Publishing uses a subscriber snapshot taken when publication starts. Subscribing or unsubscribing during publication affects later publications, not the current one.
- Cancellation is observed before each subscriber is invoked. Cancellation-aware subscribers receive the token passed to `PublishAsync`.
- Static handlers remain alive for the lifetime of the event source. Instance handlers, including capturing lambdas, are held weakly.
- Synchronous exceptions propagate as their original exception type, while asynchronous exceptions are propagated after awaiting the handler.
- Multicast delegates subscribe and unsubscribe their individual invocations.

## Installation

Install via NuGet:
Expand Down Expand Up @@ -73,11 +82,11 @@ public record MyEventData(string Message);
* `Subscribe(Action handler)`\
`Subscribe(Func<Task> handler)`\
`Subscribe(Func<CancellationToken, Task> handler)`\
Subscribes the specified handler to the event. The handler will be invoked when the event is raised, provided that its target is still alive.
Subscribes the specified handler to the event. A multicast delegate subscribes each invocation. The handlers will be invoked when the event is raised, provided that their targets are still alive.
* `Unsubscribe(Action handler)`\
`Unsubscribe(Func<Task> handler)`\
`Unsubscribe(Func<CancellationToken, Task> handler)`\
Unsubscribes the specified handler from the event.
Unsubscribes the specified handler from the event. A multicast delegate unsubscribes all matching invocations.
* `PublishAsync(CancellationToken cancellationToken = default)`\
Raises the event by invoking all live subscribers. Dead subscribers (whose targets have been garbage-collected) are removed.

Expand All @@ -87,10 +96,10 @@ public record MyEventData(string Message);
* `Subscribe(Action<TEvent> handler)`\
`Subscribe(Func<TEvent, Task> handler)`\
`Subscribe(Func<TEvent, CancellationToken, Task> handler)`\
Subscribes the specified handler to the event. The handler will be invoked when the event is raised, provided that its target is still alive.
Subscribes the specified handler to the event. A multicast delegate subscribes each invocation. The handlers will be invoked when the event is raised, provided that their targets are still alive.
* `Unsubscribe(Action<TEvent> handler)`\
`Unsubscribe(Func<TEvent, Task> handler)`\
`Unsubscribe(Func<TEvent, CancellationToken, Task> handler)`\
Unsubscribes the specified handler from the event.
Unsubscribes the specified handler from the event. A multicast delegate unsubscribes all matching invocations.
* `PublishAsync(TEvent eventData, CancellationToken cancellationToken = default)`\
Raises the event by invoking all live subscribers with the provided event data. Dead subscribers (whose targets have been garbage-collected) are removed.
Loading