using System;
using System.Threading;
namespace ZeroLevel.Services.Shedulling
{
///
/// A wrapper around an Action that stores the time at which an action should be performed, as well as a link to the next action.
///
internal sealed class ExpiredObject
{
private static long _counter = 0;
internal static void ResetIndex(long index)
=> _counter = index;
public ExpiredObject()
{
Key = Interlocked.Increment(ref _counter);
if (Key == -1)
Key = Interlocked.Increment(ref _counter);
}
public ExpiredObject(bool has_no_key)
{
if (has_no_key)
Key = -1;
else
Key = Interlocked.Increment(ref _counter);
}
public ExpiredObject Reset(DateTime nextDate)
{
ExpirationDate = nextDate;
Next = null;
return this;
}
///
/// Action at the end of the wait
///
public Action Callback;
///
///Expiration Timeout
///
public DateTime ExpirationDate;
///
/// Next object with the nearest waiting date
///
public ExpiredObject Next;
///
/// Key to identify the pending event
///
public long Key { get; }
}
}