servuo/Scripts/Misc/TaskPollingTimer.cs
TrueUO 528c0e0459 Made private fields readonly, where possible.
If a class has a field that's not marked readonly but is only set in the constructor, it could cause confusion about the field's intended use. To avoid confusion, such fields should be marked readonly to make their intended use explicit, and to prevent future maintainers from inadvertently changing their use.
2020-04-15 10:13:04 -04:00

27 lines
626 B
C#

using System;
using System.Threading.Tasks;
namespace Server
{
public class TaskPollingTimer<T> : Timer
{
private readonly Task<T> m_Task;
private readonly Action<T> m_Callback;
public TaskPollingTimer(Task<T> task, Action<T> callback)
: base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
{
m_Task = task;
m_Callback = callback;
}
protected override void OnTick()
{
if (m_Task.IsCompleted)
{
m_Callback(m_Task.Result);
Stop();
}
}
}
}