using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace Wabbajack.Common.CSP { public class TakeTaskHandler : Handler>> { private readonly bool _blockable; private readonly TaskCompletionSource _tcs; public TakeTaskHandler(TaskCompletionSource tcs = null, bool blockable = true) { _blockable = blockable; _tcs = tcs ?? new TaskCompletionSource(); } public bool IsActive => true; public bool IsBlockable => _blockable; public uint LockId => 0; public Task Task => _tcs.Task; public Action> Commit() { return Handle; } private void Handle(Box a) { if (a.IsSet) _tcs.SetResult(a.Value); _tcs.SetCanceled(); } } }