Files
TEngine/Assets/GameScripts/DotNet/Core/Task/FCancellationToken.cs
ALEXTANG 0c8f3a5f92 [+] TEngineServer
[+] TEngineServer
2023-07-13 17:17:26 +08:00

47 lines
987 B
C#

using System;
using System.Collections.Generic;
#pragma warning disable CS8625
namespace TEngine
{
public sealed class FCancellationToken
{
private HashSet<Action> _actions = new HashSet<Action>();
public bool IsCancel => _actions == null;
public void Add(Action action)
{
_actions.Add(action);
}
public void Remove(Action action)
{
_actions.Remove(action);
}
public void Cancel()
{
if (_actions == null)
{
return;
}
var runActions = _actions;
_actions = null;
foreach (var action in runActions)
{
try
{
action.Invoke();
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
}