Created
May 3, 2017 22:27
-
-
Save darraghjones/29bb4a3daecb17dc8e948c9bc530fe6b to your computer and use it in GitHub Desktop.
Subject backed in-memory message broker
This file contains 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
class MemBroker : IDisposable | |
{ | |
private readonly Subject<object> s = new Subject<object>(); | |
public IDisposable Register<T>(Action<T> handler) | |
{ | |
return s.Subscribe(o => | |
{ | |
if (o is T) handler((T)o); | |
}); | |
} | |
public void Send<T>(T message) | |
{ | |
s.OnNext(message); | |
} | |
public void Dispose() | |
{ | |
s.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment