public static IDisposable AutoRun(Action reaction, Action <Exception> exceptionHandler = null) { var atom = new ReactionAtom(reaction, exceptionHandler); atom.Get(); return(atom); }
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); }