Created
June 3, 2021 16:07
-
-
Save neuecc/17d48de3c02ca46731dcc1d07ee19d27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MessagePipe; | |
| |
public struct MyEvent { } | |
| |
public class SceneA | |
{ | |
readonly IPublisher<MyEvent> publisher; | |
public SceneA(IPublisher<MyEvent> publisher) | |
{ | |
this.publisher = publisher; | |
} | |
| |
void Send() | |
{ | |
this.publisher.Publish(new MyEvent()); | |
} | |
} | |
| |
public class SceneB | |
{ | |
readonly ISubscriber<MyEvent> subscriber; | |
readonly IDisposable disposable; | |
| |
public SceneB(ISubscriber<MyEvent> subscriber) | |
{ | |
var bag = DisposableBag.CreateBuilder(); // composite disposable for manage subscription | |
subscriber.Subscribe(x => Console.WriteLine("here")).AddTo(bag); | |
| |
disposable = bag.Build(); | |
} | |
| |
void Close() | |
{ | |
disposable.Dispose(); // unsubscribe event, all subscription **must** Dispose when completed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment