Skip to content

Instantly share code, notes, and snippets.

@darraghjones
Created May 3, 2017 22:27
Show Gist options
  • Save darraghjones/29bb4a3daecb17dc8e948c9bc530fe6b to your computer and use it in GitHub Desktop.
Save darraghjones/29bb4a3daecb17dc8e948c9bc530fe6b to your computer and use it in GitHub Desktop.
Subject backed in-memory message broker
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