virtualx-engine/modules/mono/glue/Managed/Files/GodotSynchronizationContext.cs

25 lines
730 B
C#
Raw Normal View History

2017-10-02 23:24:00 +02:00
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
namespace Godot
{
2018-09-07 03:08:16 +02:00
public class GodotSynchronizationContext : SynchronizationContext
{
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> _queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
2017-10-02 23:24:00 +02:00
2018-09-07 03:08:16 +02:00
public override void Post(SendOrPostCallback d, object state)
{
_queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
2018-09-07 03:08:16 +02:00
}
2017-10-02 23:24:00 +02:00
2018-09-07 03:08:16 +02:00
public void ExecutePendingContinuations()
{
while (_queue.TryTake(out var workItem))
2018-09-07 03:08:16 +02:00
{
workItem.Key(workItem.Value);
}
}
}
2017-10-02 23:24:00 +02:00
}