From ef5aee87f38d11f56f335df8ff28da66f66a621a Mon Sep 17 00:00:00 2001
From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com>
Date: Sun, 5 Dec 2021 22:55:24 -0800
Subject: [PATCH] fix: Adds back generic timer delay call (#880)
---
Projects/Server/Timer/Timer.DelayStateCall.cs | 242 ++++++++++++++++++
1 file changed, 242 insertions(+)
create mode 100644 Projects/Server/Timer/Timer.DelayStateCall.cs
diff --git a/Projects/Server/Timer/Timer.DelayStateCall.cs b/Projects/Server/Timer/Timer.DelayStateCall.cs
new file mode 100644
index 000000000..5c7712e55
--- /dev/null
+++ b/Projects/Server/Timer/Timer.DelayStateCall.cs
@@ -0,0 +1,242 @@
+/*************************************************************************
+ * ModernUO *
+ * Copyright 2019-2021 - ModernUO Development Team *
+ * Email: hi@modernuo.com *
+ * File: Timer.DelayStateCall.cs *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see . *
+ *************************************************************************/
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace Server
+{
+ public partial class Timer
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(Action callback, T state) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(TimeSpan delay, Action callback, T state) =>
+ DelayCall(delay, TimeSpan.Zero, 1, callback, state);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, Action callback, T state) =>
+ DelayCall(delay, interval, 0, callback, state);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, Action callback, T state) =>
+ new DelayStateCallTimer(delay, interval, count, callback, state).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(Action callback, T1 t1, T2 t2) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(TimeSpan delay, Action callback, T1 t1, T2 t2) =>
+ DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(TimeSpan delay, TimeSpan interval, Action callback, T1 t1, T2 t2) =>
+ DelayCall(delay, interval, 0, callback, t1, t2);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval, int count, Action callback,
+ T1 t1, T2 t2
+ ) => new DelayStateCallTimer(delay, interval, count, callback, t1, t2).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(Action callback, T1 t1, T2 t2, T3 t3) =>
+ DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, Action callback, T1 t1, T2 t2, T3 t3
+ ) => DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2, t3);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval, Action callback,
+ T1 t1, T2 t2, T3 t3
+ ) => DelayCall(delay, interval, 0, callback, t1, t2, t3);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval, int count,
+ Action callback, T1 t1, T2 t2, T3 t3
+ ) => new DelayStateCallTimer(delay, interval, count, callback, t1, t2, t3).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4
+ ) => DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3, t4);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, Action callback,
+ T1 t1, T2 t2, T3 t3, T4 t4
+ ) => DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2, t3, t4);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval,
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4
+ ) => DelayCall(delay, interval, 0, callback, t1, t2, t3, t4);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval, int count,
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4
+ ) => new DelayStateCallTimer(delay, interval, count, callback, t1, t2, t3, t4).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
+ ) => new DelayStateCallTimer(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3, t4, t5).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay,
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
+ ) => new DelayStateCallTimer(delay, TimeSpan.Zero, 1, callback, t1, t2, t3, t4, t5).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval,
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
+ ) => new DelayStateCallTimer(delay, interval, 0, callback, t1, t2, t3, t4, t5).Start();
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static Timer DelayCall(
+ TimeSpan delay, TimeSpan interval, int count,
+ Action callback, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
+ ) => new DelayStateCallTimer(delay, interval, count, callback, t1, t2, t3, t4, t5).Start();
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T _t1;
+
+ public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, Action callback, T state)
+ : base(delay, interval, count)
+ {
+ Callback = callback;
+ _t1 = state;
+ }
+
+ public Action Callback { get; }
+
+ protected override void OnTick() => Callback?.Invoke(_t1);
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 _t1;
+ private readonly T2 _t2;
+
+ public DelayStateCallTimer(
+ TimeSpan delay, TimeSpan interval, int count, Action callback,
+ T1 t1, T2 t2
+ ) : base(delay, interval, count)
+ {
+ Callback = callback;
+ _t1 = t1;
+ _t2 = t2;
+ }
+
+ public Action Callback { get; }
+
+ protected override void OnTick() => Callback?.Invoke(_t1, _t2);
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 _t1;
+ private readonly T2 _t2;
+ private readonly T3 _t3;
+
+ public DelayStateCallTimer(
+ TimeSpan delay, TimeSpan interval, int count, Action callback,
+ T1 t1, T2 t2, T3 t3
+ ) : base(delay, interval, count)
+ {
+ Callback = callback;
+ _t1 = t1;
+ _t2 = t2;
+ _t3 = t3;
+ }
+
+ public Action Callback { get; }
+
+ protected override void OnTick() => Callback?.Invoke(_t1, _t2, _t3);
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 _t1;
+ private readonly T2 _t2;
+ private readonly T3 _t3;
+ private readonly T4 _t4;
+
+ public DelayStateCallTimer(
+ TimeSpan delay, TimeSpan interval, int count, Action callback,
+ T1 t1, T2 t2, T3 t3, T4 t4
+ ) : base(delay, interval, count)
+ {
+ Callback = callback;
+ _t1 = t1;
+ _t2 = t2;
+ _t3 = t3;
+ _t4 = t4;
+ }
+
+ public Action Callback { get; }
+
+ protected override void OnTick() => Callback?.Invoke(_t1, _t2, _t3, _t4);
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+
+ private class DelayStateCallTimer : Timer
+ {
+ private readonly T1 _t1;
+ private readonly T2 _t2;
+ private readonly T3 _t3;
+ private readonly T4 _t4;
+ private readonly T5 _t5;
+
+ public DelayStateCallTimer(
+ TimeSpan delay, TimeSpan interval, int count, Action callback,
+ T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
+ ) : base(delay, interval, count)
+ {
+ Callback = callback;
+ _t1 = t1;
+ _t2 = t2;
+ _t3 = t3;
+ _t4 = t4;
+ _t5 = t5;
+ }
+
+ public Action Callback { get; }
+
+ protected override void OnTick() => Callback?.Invoke(_t1, _t2, _t3, _t4, _t5);
+
+ public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
+ }
+ }
+}