mirror of
https://github.com/Ikatono/TwitchIrcClient.git
synced 2025-10-29 04:56:12 -05:00
attempted fix to RateLimiter, not fully tested yet
This commit is contained in:
@@ -29,29 +29,36 @@ namespace TwitchIrcClient.IRC
|
|||||||
Timer.Start();
|
Timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WaitForAvailable(CancellationToken? token = null)
|
public bool WaitForAvailable(CancellationToken? token = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
lock (Semaphore)
|
||||||
{
|
{
|
||||||
if (token is CancellationToken actualToken)
|
if (token is CancellationToken actualToken)
|
||||||
Semaphore.Wait(actualToken);
|
Semaphore.Wait(actualToken);
|
||||||
else
|
else
|
||||||
Semaphore.Wait();
|
Semaphore.Wait();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
//caller is responsible for checking whether connection is cancelled before trying to send
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool WaitForAvailable(TimeSpan timeout, CancellationToken? token = null)
|
public bool WaitForAvailable(TimeSpan timeout, CancellationToken? token = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
lock (Semaphore)
|
||||||
{
|
{
|
||||||
if (token is CancellationToken actualToken)
|
if (token is CancellationToken actualToken)
|
||||||
return Semaphore.Wait(timeout, actualToken);
|
return Semaphore.Wait(timeout, actualToken);
|
||||||
else
|
else
|
||||||
return Semaphore.Wait(timeout);
|
return Semaphore.Wait(timeout);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -60,12 +67,15 @@ namespace TwitchIrcClient.IRC
|
|||||||
public bool WaitForAvailable(int millis, CancellationToken? token = null)
|
public bool WaitForAvailable(int millis, CancellationToken? token = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
lock (Semaphore)
|
||||||
{
|
{
|
||||||
if (token is CancellationToken actualToken)
|
if (token is CancellationToken actualToken)
|
||||||
return Semaphore.Wait(millis, actualToken);
|
return Semaphore.Wait(millis, actualToken);
|
||||||
else
|
else
|
||||||
return Semaphore.Wait(millis);
|
return Semaphore.Wait(millis);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -76,16 +86,13 @@ namespace TwitchIrcClient.IRC
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Semaphore.Release(MessageLimit);
|
lock (Semaphore)
|
||||||
}
|
|
||||||
catch (SemaphoreFullException)
|
|
||||||
{
|
{
|
||||||
|
Semaphore.Release(MessageLimit - Semaphore.CurrentCount);
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (SemaphoreFullException) { }
|
||||||
|
catch (ObjectDisposedException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
#region RateLimiter Dispose
|
#region RateLimiter Dispose
|
||||||
|
|||||||
Reference in New Issue
Block a user