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