public async Task RunWhenConcurrent_PrevMustFail() { var once = new ConcurrentOnce(); var ok1 = once.WaitAsync(TimeSpan.FromSeconds(1)); var ok2 = await once.WaitAsync(TimeSpan.Zero); Assert.IsTrue(ok2); Assert.IsFalse(await ok1); }
private async Task CoreHandler() { var canEnter = await once.WaitAsync(BindSettings.DelayTime); if (canEnter && Interlocked.CompareExchange(ref notify, 0, 1) == 1) { try { var infos = ChangeWatcher.ChangeInfos; ChangeWatcher.Clear(); var repo = ChangeReport.FromChanges(GetConfiguration(), infos); var saver = new ChangeSaver(repo, BindSettings.Conditions); saver.EmitAndSave(); OnConfigChanged(infos); Saved?.Invoke(this, infos); } catch (Exception ex) { SaveException?.Invoke(this, ex); } finally { Interlocked.Exchange(ref notify, 1); } } }
public async Task RunOnce_MustReturnTrue() { var once = new ConcurrentOnce(); var ok = await once.WaitAsync(TimeSpan.Zero); Assert.IsTrue(ok); once.ToString(); }
public async Task RunWhenExchanged_MustReturnFail() { var once = new ConcurrentOnce(); var res1 = once.WaitAsync(TimeSpan.FromSeconds(3)); var res2 = once.Exchange(); Assert.IsTrue(res2); Assert.IsFalse(await res1); }
public async Task RunAfter_TokenMustChanged() { var once = new ConcurrentOnce(); var tk1 = once.Token; await once.WaitAsync(TimeSpan.Zero); var tk2 = once.Token; Assert.AreNotEqual(tk1, tk2); }
private async Task CoreHandler() { if (notify && await once.WaitAsync(BindSettings.DelayTime)) { try { var infos = ChangeWatcher.ChangeInfos; ChangeWatcher.Clear(); var repo = ChangeReport.FromChanges(ChangeNotifyable, infos); var saver = new ChangeSaver(repo, BindSettings.Conditions); var res = saver.EmitAndSave(); Updater(BindValue); Saved?.Invoke(this, infos); } catch (Exception ex) { SaveException?.Invoke(this, ex); } } }