view Implab/FuncChainTask.cs @ 179:478ef706906a ref20160224

sync
author cin
date Wed, 23 Mar 2016 19:52:08 +0300
parents eb793fbbe4ea
children dd4a3590f9c6
line wrap: on
line source

using System;

namespace Implab {
    public class FuncChainTask<TResult> : FuncChainTaskBase<TResult>, IDeferred {
        readonly Func<IPromise<TResult>> m_task;

        public FuncChainTask(Func<IPromise<TResult>> task, Func<Exception, IPromise<TResult>> error, Func<Exception, IPromise<TResult>> cancel, bool autoCancellable)
            : base(error, cancel, autoCancellable) {
            m_task = task;
        }

        public void Resolve() {
            if (m_task != null && LockCancelation()) {
                try {
                    var operation = m_task();
                    operation.On(SetResult, HandleErrorInternal, SetCancelled);
                    CancellationRequested(operation.Cancel);
                } catch (Exception err) {
                    HandleErrorInternal(err);
                }
            }
        }
    }
}