2024-08-12 13:49:36 -04:00
|
|
|
using TwitchChatTTS.Chat.Speech;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Observers
|
|
|
|
{
|
|
|
|
public class TTSPublisher : IObservable<TTSGroupedMessage>
|
|
|
|
{
|
|
|
|
private readonly HashSet<IObserver<TTSGroupedMessage>> _observers;
|
|
|
|
|
|
|
|
|
|
|
|
public TTSPublisher()
|
|
|
|
{
|
|
|
|
_observers = new();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IDisposable Subscribe(IObserver<TTSGroupedMessage> observer)
|
|
|
|
{
|
2024-11-08 10:26:10 -05:00
|
|
|
_observers.Add(observer);
|
2024-08-12 13:49:36 -04:00
|
|
|
return new Unsubscriber<TTSGroupedMessage>(_observers, observer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal sealed class Unsubscriber<T> : IDisposable
|
|
|
|
{
|
|
|
|
private readonly ISet<IObserver<T>> _observers;
|
|
|
|
private readonly IObserver<T> _observer;
|
|
|
|
|
|
|
|
internal Unsubscriber(ISet<IObserver<T>> observers, IObserver<T> observer)
|
|
|
|
=> (_observers, _observer) = (observers, observer);
|
|
|
|
|
|
|
|
public void Dispose() => _observers.Remove(_observer);
|
|
|
|
}
|
|
|
|
}
|