qstbak/Questionable/Questionable.Controller.Steps.Common/AbstractDelayedTaskExecutor.cs
2025-10-09 07:47:19 +10:00

43 lines
820 B
C#

using System;
namespace Questionable.Controller.Steps.Common;
internal abstract class AbstractDelayedTaskExecutor<T> : TaskExecutor<T> where T : class, ITask
{
private DateTime _continueAt;
protected TimeSpan Delay { get; set; }
protected AbstractDelayedTaskExecutor()
: this(TimeSpan.FromSeconds(5L))
{
}
protected AbstractDelayedTaskExecutor(TimeSpan delay)
{
Delay = delay;
}
protected sealed override bool Start()
{
bool result = StartInternal();
_continueAt = DateTime.Now.Add(Delay);
return result;
}
protected abstract bool StartInternal();
public override ETaskResult Update()
{
if (_continueAt >= DateTime.Now)
{
return ETaskResult.StillRunning;
}
return UpdateInternal();
}
protected virtual ETaskResult UpdateInternal()
{
return ETaskResult.TaskComplete;
}
}