2019-11-09 06:37:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Common.CSP
|
|
|
|
|
{
|
|
|
|
|
class PutTaskHandler<T> : Handler<Action<bool>>
|
|
|
|
|
{
|
|
|
|
|
private readonly bool _blockable;
|
2019-11-10 22:15:52 +00:00
|
|
|
|
private TaskCompletionSource<bool> _tcs = new TaskCompletionSource<bool>();
|
2019-11-09 06:37:05 +00:00
|
|
|
|
|
2019-11-09 14:49:00 +00:00
|
|
|
|
public PutTaskHandler(bool blockable = true)
|
2019-11-09 06:37:05 +00:00
|
|
|
|
{
|
|
|
|
|
_blockable = blockable;
|
2019-11-09 14:49:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TaskCompletionSource<bool> TaskCompletionSource
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_tcs == null)
|
|
|
|
|
_tcs = new TaskCompletionSource<bool>();
|
|
|
|
|
return _tcs;
|
|
|
|
|
}
|
2019-11-09 06:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsActive => true;
|
|
|
|
|
public bool IsBlockable => _blockable;
|
|
|
|
|
public uint LockId => 0;
|
|
|
|
|
public Action<bool> Commit()
|
|
|
|
|
{
|
|
|
|
|
return Handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Handle(bool val)
|
|
|
|
|
{
|
2019-11-10 00:22:28 +00:00
|
|
|
|
TaskCompletionSource.SetResult(val);
|
2019-11-09 06:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|