예제 #1
0
파일: Atom.cs 프로젝트: Mefodei/UniMob
        public static IDisposable AutoRun(Action reaction, Action <Exception> exceptionHandler = null)
        {
            var atom = new ReactionAtom(reaction, exceptionHandler);

            atom.Get();
            return(atom);
        }
예제 #2
0
파일: Atom.cs 프로젝트: Mefodei/UniMob
        public static IDisposable Reaction <T>(
            AtomPull <T> pull,
            Action <T, IDisposable> reaction,
            IEqualityComparer <T> comparer      = null,
            bool fireImmediately                = false,
            Action <Exception> exceptionHandler = null)
        {
            var  valueAtom = Computed(pull, comparer: comparer);
            bool firstRun  = true;

            ReactionAtom atom = null;

            atom = new ReactionAtom(() =>
            {
                var value = valueAtom.Value;

                using (NoWatch)
                {
                    if (firstRun)
                    {
                        firstRun = false;

                        if (!fireImmediately)
                        {
                            return;
                        }
                    }

                    // ReSharper disable once AccessToModifiedClosure
                    reaction(value, atom);
                }
            }, exceptionHandler);

            atom.Get();
            return(atom);
        }