Last active
July 3, 2020 10:46
-
-
Save korchoon/4f8c2352c50c912e33f1811fc8bdca87 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
public class Subject<T> : IDisposable { | |
Action<T> _action; | |
bool _disposed; | |
public void Subscribe(Action<T> a) { | |
Asr.IsFalse(_disposed); | |
_action += a; | |
} | |
public void Publish(T msg) { | |
Asr.IsFalse(_disposed); | |
_action.Invoke(msg); | |
} | |
public void Dispose() { | |
Asr.IsFalse(_disposed); | |
_disposed = true; | |
_action = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment