Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.

Commit d7fc9c2

Browse files
committed
Update README
1 parent 9d14dd4 commit d7fc9c2

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ messageBus.Subscribe<FooMessage>(async (msg, cancellationToken) =>
105105
await messageBus.PublishAsync(new FooMessage(), cancellationToken);
106106
```
107107

108-
#### Subscription
108+
#### Unsubscribe
109109

110+
There are 2 ways to unsubscribe.
111+
112+
#### 1. `IDisposable`
110113

111114
`Subscribe` returns `IDisposable`.
112115
Disposing of this will unsubscribe.
@@ -119,10 +122,27 @@ subscription.Dispose();
119122
The `AddTo` extension to UniTask is useful.
120123

121124
```csharp
122-
messageBus.Subscribe<FooMessage>(...)
123-
.AddTo(cancellationToken);
125+
messageBus.Subscribe<FooMessage>(msg =>
126+
{
127+
// ...
128+
})
129+
.AddTo(...);
124130
```
125131

132+
#### 2. `CancellationToken`
133+
134+
You can pass a cancellationToken to Subscribe.
135+
136+
```csharp
137+
messageBus.Subscribe<FooMessage>(msg =>
138+
{
139+
// ...
140+
}, cancellationToken);
141+
```
142+
143+
When this token is canceled, it will be unsubscribed.
144+
145+
126146
#### Filter
127147

128148
AsyncMessageBus can insert any preprocessing or postprocessing into publish.

0 commit comments

Comments
 (0)