initial commit

This commit is contained in:
robotics_x1
2026-10-12 15:24:08 +07:00
commit 55228b3772
367 changed files with 162893 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
namespace Lab505.Script;
/// <summary>Per-user CancellationTokenSource registry. Thread-safe.</summary>
public sealed class ScriptCancelService
{
private readonly object _lock = new();
private readonly Dictionary<int, CancellationTokenSource> _map = new();
public CancellationToken Register(int userId, out CancellationTokenSource cts)
{
lock (_lock)
{
if (_map.TryGetValue(userId, out var old)) { old.Cancel(); old.Dispose(); }
cts = new CancellationTokenSource();
_map[userId] = cts;
return cts.Token;
}
}
public void Cancel(int userId)
{
lock (_lock)
{
if (_map.TryGetValue(userId, out var cts)) cts.Cancel();
}
}
public void Clear(int userId)
{
lock (_lock)
{
if (_map.TryGetValue(userId, out var cts)) { cts.Dispose(); _map.Remove(userId); }
}
}
// Legacy single-user helpers (kept for backward compat)
public void Cancel() { lock (_lock) { foreach (var c in _map.Values) c.Cancel(); } }
public void Clear() { lock (_lock) { foreach (var c in _map.Values) c.Dispose(); _map.Clear(); } }
}