using System;
using System.Threading;

namespace Plane
{
    public static class SynchronizationContextExtensions
    {
        public static void Post(this SynchronizationContext syncContext, Action action)
        {
            if (SynchronizationContext.Current == syncContext)
            {
                action();
            }
            else
            {
                syncContext.Post(state => action(), null);
            }
        }

        public static void Send(this SynchronizationContext syncContext, Action action)
        {
            if (SynchronizationContext.Current == syncContext)
            {
                action();
            }
            else
            {
                syncContext.Send(state => action(), null);
            }
        }
    }
}
