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
|
|
|
|
{
|
2019-07-18 04:08:24 +02:00
|
|
|
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)
|
|
|
|
{
|
2019-07-18 04:08:24 +02:00
|
|
|
_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()
|
|
|
|
{
|
2019-07-18 04:08:24 +02:00
|
|
|
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
|
|
|
}
|