using System.Threading; using System; namespace Implab { public class SyncContextPromise : Promise { readonly SynchronizationContext m_context; public SyncContextPromise(SynchronizationContext context) { Safe.ArgumentNotNull(context, "context"); m_context = context; } protected override void SignalSuccess(IDeferred handler) { m_context.Post(x => base.SignalSuccess(handler), null); } protected override void SignalError(IDeferred handler, Exception error) { m_context.Post(x => base.SignalError(handler, error), null); } protected override void SignalCancelled(IDeferred handler, Exception reason) { m_context.Post(x => base.SignalCancelled(handler, reason), null); } } }