示例#1
0
        public async Task SimulateWork(TimeSpan ms, CancellationToken token)
        {
            //_machine.RecordActivity();
            await SimDelayTask.Delay(ms, token);

            //_machine.RecordActivity();
        }
示例#2
0
        public Task Send(SimPacket msg)
        {
            if (_def.PacketLoss != null && _def.PacketLoss(_network.Rand))
            {
                Debug(LogType.Fault, msg, $"LOST {msg.BodyString()}", _def.LogFaults);
                // we just lost a packet.
                return(Task.FromResult(true));
            }
            Debug(LogType.Info, msg, $"Send {msg.BodyString()}");

            // TODO: network cancellation
            _factory.StartNew(async() => {
                // delivery wait
                try {
                    var latency = _def.Latency(_network.Rand);
                    await SimDelayTask.Delay(latency);
                    _network.InternalDeliver(msg);
                } catch (Exception ex) {
                    Debug(LogType.Error, msg, $"FATAL: {ex}");
                }
            });
            return(Task.FromResult(true));
        }
示例#3
0
 public Task Delay(TimeSpan i, CancellationToken token = default(CancellationToken))
 {
     return(SimDelayTask.Delay(i, token));
 }