using System; namespace UnityTcp.Editor.Helpers { /// /// Ambient context for the command currently being dispatched. The dispatching loop sets it /// right before a handler runs and clears it afterwards, so a HandleCommand(JObject) /// can read the native request id (to start a runner job) without changing its prototype. /// /// Commands are dispatched serially per thread — the editor main loop and the /// worker each set/clear around a handler — so the /// backing fields are thread-local to keep the two dispatchers from seeing each other's /// context. /// public static class CommandContext { [ThreadStatic] private static ulong _requestId; [ThreadStatic] private static string _commandType; /// Native request id of the command being handled (for EnqueueResponse). public static ulong RequestId => _requestId; /// Command type of the command being handled (usable as a job name). public static string CommandType => _commandType; public static void Set(ulong requestId, string commandType) { _requestId = requestId; _commandType = commandType; } public static void Clear() { _requestId = 0; _commandType = null; } } }