view Implab/PromiseReaction`1.cs @ 246:5aa9cfbe56c3 v3

missing files
author cin
date Fri, 26 Jan 2018 11:19:38 +0300
parents
children fb70574741a1
line wrap: on
line source

using System;

namespace Implab {
    public class PromiseReaction<T> : IResolvable<T> {
        IDispatcher m_dispatcher;

        Action<T> m_onFulfilledJob;

        Action<Exception> m_onRejectedJob;

        public void Reject(Exception error) {
            if (m_dispatcher != null)
                m_dispatcher.Enqueue(() => m_onRejectedJob(error));
            else
                m_onRejectedJob(error);
        }

        public void Resolve(T result) {
            if (m_dispatcher != null)
                m_dispatcher.Enqueue(() => m_onFulfilledJob(result));
            else
                m_onFulfilledJob(result);
        }
    }
}