Added a simple method for subscribing to events.

This commit is contained in:
Tom
2025-01-07 15:42:10 +00:00
parent 64cb0c1f6d
commit b724cd00eb
4 changed files with 15 additions and 8 deletions

View File

@@ -37,7 +37,7 @@ namespace TwitchChatTTS.Bus
{
if (!_topics.TryGetValue(topic, out var bus))
{
bus = new ServiceBusObservable(topic, this);
bus = new ServiceBusObservable(topic, this, _logger);
_topics.Add(topic, bus);
}
return bus;

View File

@@ -1,4 +1,5 @@
using System.Reactive;
using Serilog;
namespace TwitchChatTTS.Bus
{
@@ -6,11 +7,13 @@ namespace TwitchChatTTS.Bus
{
private readonly string _topic;
private readonly ServiceBusCentral _central;
private readonly ILogger _logger;
public ServiceBusObservable(string topic, ServiceBusCentral central)
public ServiceBusObservable(string topic, ServiceBusCentral central, ILogger logger)
{
_topic = topic;
_central = central;
_logger = logger;
}
protected override IDisposable SubscribeCore(IObserver<ServiceBusData> observer)
@@ -19,6 +22,10 @@ namespace TwitchChatTTS.Bus
return new ServiceBusUnsubscriber(_topic, _central, observer);
}
public IDisposable Subscribe(Action<ServiceBusData> action) {
return Subscribe(new ServiceBusObserver(action, _logger));
}
private sealed class ServiceBusUnsubscriber : IDisposable
{
private readonly string _topic;