view Implab/FuncTask.cs @ 163:419aa51b04fd ref20160224

JSON moved to Formats namespace Working in RegularDFA
author cin
date Wed, 24 Feb 2016 20:12:52 +0300
parents eb793fbbe4ea
children dd4a3590f9c6
line wrap: on
line source

using System;
using System.Threading;

namespace Implab {
    public class FuncTask<T> : FuncTaskBase<T>, IDeferred {
        readonly Func<T> m_task;

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

        public void Resolve() {
            if (m_task != null && LockCancelation()) {
                try {
                    SetResult(m_task());
                } catch(Exception err) {
                    HandleErrorInternal(err);
                }
            }
        }
    }
}