allow CancellationToken
This commit is contained in:
parent
4841c43755
commit
039054ad9e
|
|
@ -1,8 +1,12 @@
|
|||
using System.Threading;
|
||||
|
||||
namespace BotSharp.Abstraction.Infrastructures.Events;
|
||||
|
||||
public interface IEventSubscriber
|
||||
{
|
||||
Task SubscribeAsync(string channel, Func<string, string, Task> received);
|
||||
|
||||
Task SubscribeAsync(string channel, string group, bool priorityEnabled, Func<string, string, Task> received);
|
||||
Task SubscribeAsync(string channel, string group, bool priorityEnabled,
|
||||
Func<string, string, Task> received,
|
||||
CancellationToken? stoppingToken = null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ public class RedisSubscriber : IEventSubscriber
|
|||
});
|
||||
}
|
||||
|
||||
public async Task SubscribeAsync(string channel, string group, bool priorityEnabled, Func<string, string, Task> received)
|
||||
public async Task SubscribeAsync(string channel, string group, bool priorityEnabled,
|
||||
Func<string, string, Task> received,
|
||||
CancellationToken? stoppingToken = null)
|
||||
{
|
||||
var db = _redis.GetDatabase();
|
||||
|
||||
|
|
@ -44,6 +46,12 @@ public class RedisSubscriber : IEventSubscriber
|
|||
{
|
||||
await Task.Delay(100);
|
||||
|
||||
if (stoppingToken.HasValue && stoppingToken.Value.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogInformation($"Stopping consumer channel & group: [{channel}, {group}]");
|
||||
break;
|
||||
}
|
||||
|
||||
if (priorityEnabled)
|
||||
{
|
||||
if (await HandleGroupMessage(db, $"{channel}-{EventPriority.High}", group, received) > 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue