Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
41
Bus/ServiceBusObservable.cs
Normal file
41
Bus/ServiceBusObservable.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Reactive;
|
||||
|
||||
namespace TwitchChatTTS.Bus
|
||||
{
|
||||
public class ServiceBusObservable : ObservableBase<ServiceBusData>
|
||||
{
|
||||
private readonly string _topic;
|
||||
private readonly ServiceBusCentral _central;
|
||||
|
||||
public ServiceBusObservable(string topic, ServiceBusCentral central)
|
||||
{
|
||||
_topic = topic;
|
||||
_central = central;
|
||||
}
|
||||
|
||||
protected override IDisposable SubscribeCore(IObserver<ServiceBusData> observer)
|
||||
{
|
||||
_central.Add(_topic, observer);
|
||||
return new ServiceBusUnsubscriber(_topic, _central, observer);
|
||||
}
|
||||
|
||||
private sealed class ServiceBusUnsubscriber : IDisposable
|
||||
{
|
||||
private readonly string _topic;
|
||||
private readonly ServiceBusCentral _central;
|
||||
private readonly IObserver<ServiceBusData> _receiver;
|
||||
|
||||
public ServiceBusUnsubscriber(string topic, ServiceBusCentral central, IObserver<ServiceBusData> receiver)
|
||||
{
|
||||
_topic = topic;
|
||||
_central = central;
|
||||
_receiver = receiver;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_central.RemoveObserver(_topic, _receiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user