public static TEntity UpdateOrThrow <TEntity>(this IAtomicSingletonWriter <TEntity> self, Func <TEntity, TEntity> change) { return(self.AddOrUpdate(() => { var txt = String.Format("Failed to load '{0}'.", typeof(TEntity).Name); throw new InvalidOperationException(txt); }, change, AddOrUpdateHint.ProbablyExists)); }
public static TView AddOrUpdate <TView>(this IAtomicSingletonWriter <TView> self, Func <TView> factory, Action <TView> update, AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists) { return(self.AddOrUpdate(factory, view => { update(view); return view; }, hint)); }
public static TSingleton UpdateEnforcingNew <TSingleton>(this IAtomicSingletonWriter <TSingleton> self, Action <TSingleton> update) where TSingleton : new() { return(self.AddOrUpdate(() => { var singleton = new TSingleton(); update(singleton); return singleton; }, update)); }
public static TView AddOrUpdate <TView>(this IAtomicSingletonWriter <TView> self, Action <TView> update, AddOrUpdateHint hint = AddOrUpdateHint.ProbablyExists) where TView : new() { return(self.AddOrUpdate(() => new TView(), view => { update(view); return view; }, hint)); }
public void Consume(AtomicMessage message) { var entity = _singleton.AddOrUpdate(r => r.Count += 1); if (entity.Count == 5) { _sender.SendOne(new AtomicMessage(), cb => cb.AddString("finish")); } else { _sender.SendOne(new AtomicMessage()); } }