using TwitchChatTTS.Chat.Speech; namespace TwitchChatTTS.Chat.Observers { public class TTSPublisher : IObservable { private readonly HashSet> _observers; public TTSPublisher() { _observers = new(); } public IDisposable Subscribe(IObserver observer) { _observers.Add(observer); return new Unsubscriber(_observers, observer); } } internal sealed class Unsubscriber : IDisposable { private readonly ISet> _observers; private readonly IObserver _observer; internal Unsubscriber(ISet> observers, IObserver observer) => (_observers, _observer) = (observers, observer); public void Dispose() => _observers.Remove(_observer); } }