From eaacc8be6da2d8b9680f8150fa5eafa898e638d2 Mon Sep 17 00:00:00 2001 From: Albie Date: Fri, 3 Dec 2021 16:21:08 +0000 Subject: [PATCH] use a cross-thread locking system --- DragonFruit.Six.Api/Dragon6Client.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DragonFruit.Six.Api/Dragon6Client.cs b/DragonFruit.Six.Api/Dragon6Client.cs index 9e3faab3..7a57f5e1 100644 --- a/DragonFruit.Six.Api/Dragon6Client.cs +++ b/DragonFruit.Six.Api/Dragon6Client.cs @@ -12,12 +12,13 @@ using DragonFruit.Six.Api.Enums; using DragonFruit.Six.Api.Exceptions; using DragonFruit.Six.Api.Utils; +using Nito.AsyncEx; namespace DragonFruit.Six.Api { public abstract class Dragon6Client : ApiClient { - private readonly object _lock = new(); + private readonly AsyncLock _lock = new(); public static readonly CultureInfo Culture = new("en-US", false); protected Dragon6Client(string userAgent = null, UbisoftService app = UbisoftService.RainbowSix) @@ -72,13 +73,12 @@ protected virtual void ApplyToken(TokenBase token) internal void ValidateToken() { - lock (_lock) + using (_lock.Lock()) { - if (Token is null || Token.Expired) + if (Token?.Expired is not false) { // todo throw something if this is majorly expired or null Token = GetToken(); - ApplyToken(Token); } }