SboxSuperuser/Core/Commands/RequestWork.cs

A small internal record-like class holding one queued request in the SboxSuperuser command layer. It stores a request key, a fingerprint string, the delegate that produces the result, a TaskCompletionSource for the caller, cancellation registration and bookkeeping fields for started/completed state.

namespace SboxSuperuser.Core.Commands;

internal sealed class RequestWork<T>
{
	internal RequestKey Key { get; }
	internal string Fingerprint { get; }
	internal Func<Task<T>> Execute { get; set; }
	internal TaskCompletionSource<T> Completion { get; } = new( TaskCreationOptions.RunContinuationsAsynchronously );
	internal CancellationTokenRegistration Cancellation { get; set; }
	internal bool Started { get; set; }
	internal DateTimeOffset? CompletedUtc { get; set; }

	internal RequestWork( RequestKey key, string fingerprint, Func<Task<T>> execute )
	{
		Key = key;
		Fingerprint = fingerprint;
		Execute = execute;
	}
}