public void WaitNext(ref bool stop) { DataItem dataItem = _dataReader.Next(_threadId, ref stop); if (dataItem != null) { TimeSpan adjustedTarget = TimeSpan.FromTicks((long)(dataItem.TimeStamp.Ticks / _speedMultiplier)); bool execute = _scenarioHandler.SetData(dataItem.Value, adjustedTarget); if (execute) { if (adjustedTarget > _timer.Value) { _counter.AddIdle(1); _waiter.Wait(adjustedTarget, ref stop); _counter.AddIdle(-1); } } } else { stop = true; } }
public void WaitNext(ref bool stop) { _strategy.Next(_id, this); if (Action == ScheduleAction.Idle || At > Timer.Value) { _counter.AddIdle(1); while (Action == ScheduleAction.Idle && stop == false) { _waiter.Wait(At, ref stop); _strategy.Next(_id, this); } _waiter.Wait(At, ref stop); _counter.AddIdle(-1); } }
public async Task Wait_is_Awaitable() { var expected = Guid.NewGuid(); var completion = new Wait <object, Guid>(); IWait wait = completion; Assert.AreEqual(Need.None, wait.Need, "at initial state"); IFiber <object> fiber = new Mock <IFiber <object> >(MockBehavior.Strict).Object; object context = new object(); IWait <object, Guid> typed = completion; typed.Wait(async(f, c, item) => { Assert.AreEqual(Need.Call, wait.Need, "inside callback state"); Assert.AreEqual(fiber, f); Assert.AreEqual(context, c); Assert.AreEqual(expected, item.GetAwaiter().GetResult()); Assert.AreEqual(expected, await item); return(null); }); Assert.AreEqual(Need.Wait, wait.Need, "waiting state"); IPost <Guid> post = completion; post.Post(expected); Assert.AreEqual(Need.Poll, wait.Need, "need to poll state"); await typed.PollAsync(fiber, context); Assert.AreEqual(Need.Done, wait.Need, "done state"); IAwaitable <Guid> awaitable = completion; var actual = await awaitable; Assert.AreEqual(expected, actual); }
public static async Task Wait_is_Awaitable <ItemType, PostType>(PostType expected) { var completion = new Wait <object, ItemType>(); IWait wait = completion; Assert.AreEqual(Need.None, wait.Need, "at initial state"); IFiber <object> fiber = new Mock <IFiber <object> >(MockBehavior.Strict).Object; object context = new object(); IWait <object, ItemType> typed = completion; typed.Wait(async(f, c, item, token) => { Assert.AreEqual(Need.Call, wait.Need, "inside callback state"); Assert.AreEqual(fiber, f); Assert.AreEqual(context, c); Assert.AreEqual(expected, item.GetAwaiter().GetResult()); Assert.AreEqual(expected, await item); return(null); }); Assert.AreEqual(Need.Wait, wait.Need, "waiting state"); wait.Post(expected); Assert.AreEqual(Need.Poll, wait.Need, "need to poll state"); await typed.PollAsync(fiber, context, CancellationToken.None); Assert.AreEqual(Need.Done, wait.Need, "done state"); IAwaitable <ItemType> awaitable = completion; var actual = await awaitable; Assert.AreEqual(expected, actual); }