using System; using System.Threading; using System.Threading.Tasks; namespace Wabbajack.DTOs.Interventions; public class AUserIntervention : IUserIntervention { private readonly TaskCompletionSource _tcs; private readonly CancellationTokenSource _ct; protected AUserIntervention() { _tcs = new TaskCompletionSource(); _ct = new CancellationTokenSource(); } public void Cancel() { _ct.Cancel(); _tcs.SetCanceled(Token); } public bool Handled => _tcs.Task.IsCompleted; public CancellationToken Token => _ct.Token; public Task Task => _tcs.Task; public void Finish(T value) { _tcs.TrySetResult(value); _ct.Cancel(); } public void SetException(Exception exception) { _ct.Cancel(); _tcs.SetException(exception); } }