示例#1
0
    public void OrderWithSingleInAndOut(ChanBase<int> chan) {
      //this is needed: tests work correctly otherwise... this initialzes thread pool or something...
      Parallel.Invoke(Task.Delay(4).Wait, Task.Delay(3).Wait, Task.Delay(5).Wait);

      Func<Task> af = async () => {
        for (int i = -500; i < 50000; ++i)
          await chan.SendAsync(i);
        DebugCounter.Incg("test.order", "all sent");
        await chan.Close();
      };
      Func<Task> bf = async () => {
        int prev;
        int cur = int.MinValue;
        try {
          while (true) {
            prev = cur;
            cur = await chan.ReceiveAsync();
            if (cur < prev)
              Assert.GreaterOrEqual(cur, prev);
          }
        } catch (TaskCanceledException) {
          DebugCounter.Incg("test.order", "cancelled");
        }
      };

      Task.WaitAll(af(), bf());
    }