From 51ef67ae9ccf7cef0370625c649933284c279068 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 23 Mar 2022 11:43:20 -0500 Subject: [PATCH] add BroadcastAsync --- SharedLibraryCore/PartialEntities/EFClient.cs | 9 +++++++-- SharedLibraryCore/Server.cs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index 9cdd3dc60..24ea46e95 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -177,7 +177,7 @@ namespace SharedLibraryCore.Database.Models return e; } - [Obsolete] + [Obsolete("Use TellAsync")] public void Tell(IEnumerable messages) { foreach (var message in messages) @@ -188,10 +188,15 @@ namespace SharedLibraryCore.Database.Models } } - public async Task TellAsync(IEnumerable messages, CancellationToken token =default) + public async Task TellAsync(IEnumerable messages, CancellationToken token = default) { foreach (var message in messages) { + if (token.IsCancellationRequested) + { + return; + } + await Tell(message).WaitAsync(Utilities.DefaultCommandTimeout, token); } } diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index 7b4b29105..5b9211e3c 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -238,6 +238,7 @@ namespace SharedLibraryCore return e; } + [Obsolete("Use BroadcastAsync")] public void Broadcast(IEnumerable messages, EFClient sender = null) { foreach (var message in messages) @@ -248,6 +249,19 @@ namespace SharedLibraryCore } } + public async Task BroadcastAsync(IEnumerable messages, EFClient sender = null, + CancellationToken token = default) + { + foreach (var message in messages) + { + if (Manager.CancellationToken.IsCancellationRequested) + { + return; + } + + await Broadcast(message, sender).WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken); + } + } /// /// Send a message to a particular players