The EditorThread struct implements INotifyCompletion to allow asynchronous operations within the editor to queue continuations onto the main thread. It tracks whether execution occurs on the main thread via ThreadSafe.IsMainThread.
using System.Runtime.CompilerServices;
using Sandbox;
namespace HumanoidRigger.EditorTools.Engine;
internal readonly struct EditorThread : INotifyCompletion
{
public EditorThread GetAwaiter()=>this;
public bool IsCompleted=>ThreadSafe.IsMainThread;
public void OnCompleted(Action continuation)=>MainThread.Queue(continuation);
public void GetResult(){}
}