This commit is contained in:
CortexCore
2025-01-22 16:50:44 +08:00
parent 01e7e4e35e
commit 6f913eb234
2 changed files with 55 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Cysharp.Threading.Tasks;
namespace BITKit
{
@@ -70,6 +71,22 @@ namespace BITKit
return Allow ? Value : other.Invoke();
}
public async UniTask<T> IfNotAllowAsync(Func<UniTask<T>> func)
{
return Allow ? Value : await func.Invoke();
}
public async UniTask<T> SetValueThenAllowAsync(Func<UniTask<T>> func)
{
if (Allow)
{
return value;
}
value = await func.Invoke();
allow = true;
return value;
}
public void SetValueThenAllow(T newValue)
{
value = newValue;