mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
38 lines
868 B
C#
38 lines
868 B
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Wabbajack.DTOs.Interventions;
|
|
|
|
public class AUserIntervention<T> : IUserIntervention
|
|
{
|
|
private readonly TaskCompletionSource<T> _tcs;
|
|
private readonly CancellationTokenSource _ct;
|
|
|
|
protected AUserIntervention()
|
|
{
|
|
_tcs = new TaskCompletionSource<T>();
|
|
_ct = new CancellationTokenSource();
|
|
}
|
|
public void Cancel()
|
|
{
|
|
_ct.Cancel();
|
|
_tcs.SetCanceled(Token);
|
|
}
|
|
|
|
public bool Handled => _tcs.Task.IsCompleted;
|
|
public CancellationToken Token => _ct.Token;
|
|
public Task<T> Task => _tcs.Task;
|
|
|
|
public void Finish(T value)
|
|
{
|
|
_tcs.TrySetResult(value);
|
|
_ct.Cancel();
|
|
}
|
|
|
|
public void SetException(Exception exception)
|
|
{
|
|
_ct.Cancel();
|
|
_tcs.SetException(exception);
|
|
}
|
|
} |