fix: Fixes pooled timer detach (#1115)

- [X] Fixes timers not returning on detach
This commit is contained in:
Kamron Batman 2022-07-14 11:14:37 -07:00 • committed by GitHub
parent 9c374861d9
commit a4168dc219
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 804 additions and 816 deletions

View file

@ -16,48 +16,47 @@
using System;
using System.Runtime.CompilerServices;
namespace Server
namespace Server;
public struct TimerExecutionToken
{
public struct TimerExecutionToken
private Timer.DelayCallTimer _timer;
internal TimerExecutionToken(Timer.DelayCallTimer timer) => _timer = timer;
public bool Running
{
private Timer.DelayCallTimer _timer;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.Running == true;
}
internal TimerExecutionToken(Timer.DelayCallTimer timer) => _timer = timer;
public int Index
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.Index ?? 0;
}
public bool Running
public int RemainingCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.RemainingCount ?? 0;
}
public DateTime Next
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.Next ?? DateTime.MinValue;
}
public void Cancel()
{
if (_timer != null)
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.Running == true;
_timer._returnOnDetach = true;
_timer?.Stop();
_timer = null;
}
public int Index
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.Index ?? 0;
}
public int RemainingCount
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.RemainingCount ?? 0;
}
public DateTime Next
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _timer?.Next ?? DateTime.MinValue;
}
public void Cancel()
{
if (_timer != null)
{
_timer._returnOnDetach = true;
_timer?.Stop();
_timer = null;
}
this = default;
}
this = default;
}
}