using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; namespace Godot { public class GodotSynchronizationContext : SynchronizationContext { private readonly BlockingCollection> queue = new BlockingCollection>(); public override void Post(SendOrPostCallback d, object state) { queue.Add(new KeyValuePair(d, state)); } public void ExecutePendingContinuations() { KeyValuePair workItem; while (queue.TryTake(out workItem)) { workItem.Key(workItem.Value); } } } }