This repository was archived by the owner on Feb 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -105,8 +105,11 @@ messageBus.Subscribe<FooMessage>(async (msg, cancellationToken) =>
105105await 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 ` .
112115Disposing of this will unsubscribe.
@@ -119,10 +122,27 @@ subscription.Dispose();
119122The ` 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
128148AsyncMessageBus can insert any preprocessing or postprocessing into publish.
You can’t perform that action at this time.
0 commit comments