Example #1
0
        public static void receiving_async_returns_a_waiting_task_which_is_complete_by_trying_to_send_a_value(Test t)
        {
            var ch = new BufferedChannel <int>(3);
            var rt = ch.ReceiveAsync();

            if (rt == null)
            {
                t.Fatal("returned task was null");
            }
            if (rt.IsCompleted)
            {
                t.Fatal("returned task was complete");
            }
            if (ch.TrySend(2) != true)
            {
                t.Fatal("failed to send when a receiver was waiting");
            }
            if (rt.Wait(100) == false || rt.IsCompleted == false)
            {
                t.Fatal("receiver task did not complete");
            }
            if (rt.Result != 2)
            {
                t.Fatal("received value (" + rt.Result + ") is not what we sent (2)");
            }
        }
Example #2
0
        public static void trying_to_send_to_an_empty_channel_returns_true(Test t)
        {
            var ch = new BufferedChannel <int>(3);

            if (ch.TrySend(2) != true)
            {
                t.Fatal("returned true sending to an new (empty) channel");
            }
        }
Example #3
0
        public static void trySend_on_a_closed_channel_returns_false(Test t)
        {
            var ch = new BufferedChannel <int>(3);

            ch.Close();
            if (ch.TrySend(2) != false)
            {
                t.Fatal("was able to send on closed channel");
            }
        }