I have a typed message broker similar to what Caliburn provides:
public interface IMessageBroker
{
void Publish<T>(T message);
IDisposable Subscribe<T>(Action<T> subscriber);
}
How can I to convert subscriptions to IObservable?
I want an extension method, something like this:
public static IObservable<T> Subscribe<T>(this IMessageBroker messageBroker)
{
var subject = new Subject<T>();
messageBroker.Subscribe<T>(subject.OnNext);
return subject;
}
problem in this implementation is that I can't unsubscribe and so it leaks.
Better name for Subscribe method is also welcomed.