daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Feb 24th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void RunThread() {
  2.   var iter = GetAllEvents().GetEnumerator();
  3.   if (!iter.MoveNext()) {
  4.     return;
  5.   }
  6.  
  7.   DateTime lastEventTime = iter.Current.Timestamp;
  8.   FireEvent(iter.Current);
  9.  
  10.   while (iter.MoveNext()) {
  11.     MyEvent nextEvent = iter.Current;
  12.  
  13.     int timeout = (int)(nextEvent.Timestamp - lastEventTime).TotalMilliseconds;
  14.     Thread.Sleep(timeout);
  15.  
  16.     FireEvent(nextEvent);
  17.     lastEventTime = nextEvent.Timestamp;
  18.   }
  19. }
  20.    
  21. Expected timeout of 1 ms but got 15 ms.
  22. Expected timeout of 2 ms but got 13 ms.
  23. Expected timeout of 3 ms but got 15 ms.
  24. Expected timeout of 2 ms but got 13 ms.
  25. Expected timeout of 1 ms but got 13 ms.
  26. Expected timeout of 1 ms but got 15 ms.
  27. Expected timeout of 2 ms but got 13 ms.
  28. Expected timeout of 2 ms but got 40 ms.
  29.    
  30. bool ChooseRespectTimeout() {
  31.   if (this.notYetChosen) {
  32.     this.respectTimeout = ChooseRandomly()
  33.     this.notYetChosen = false
  34.     reset this.notYetChosen after random time period
  35.   }
  36.   return this.respectTimeout
  37. }
  38.  
  39. void Sleep(int timeout) {
  40.   if (ChooseRespectTimeout())
  41.     Thread.Sleep(timeout)
  42.   else
  43.     Thread.Sleep(timeout * 10)
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top