Example #1
0
        public static void VariousStateTypes()
        {
            using var trigger = new AsyncTrigger();
            var untypedWait = trigger.WaitAsync();

            False(untypedWait.IsCompleted);
            var stringWait = trigger.WaitAsync(string.Empty, str => str.Length > 0);

            False(stringWait.IsCompleted);
            var arrayWait = trigger.WaitAsync(Array.Empty <int>(), array => array.Length > 0);

            False(arrayWait.IsCompleted);

            trigger.Signal("Hello, world!");
            True(untypedWait.IsCompletedSuccessfully);
            True(stringWait.IsCompletedSuccessfully);
            False(arrayWait.IsCompleted);

            trigger.Signal(new int[1]);
            True(arrayWait.IsCompletedSuccessfully);
        }
        public static void WaitForValue2()
        {
            var state = new State {
                Value = 0
            };

            using var trigger = new AsyncTrigger();
            var eventNode = trigger.WaitAsync();

            False(eventNode.IsCompleted);
            var valueNode = trigger.WaitAsync(state, i => i.Value == 42);

            False(valueNode.IsCompleted);
            trigger.Signal();
            True(eventNode.IsCompletedSuccessfully);
            False(valueNode.IsCompleted);
            trigger.Signal(state, ModifyState, 14);
            Equal(14, state.Value);
            False(valueNode.IsCompleted);
            trigger.Signal(state, ModifyState);
            True(valueNode.IsCompletedSuccessfully);
            Equal(42, state.Value);
        }
Example #3
0
        public static void WaitForValue()
        {
            var state = new State {
                Value = 0
            };

            using var trigger = new AsyncTrigger();
            var eventNode = trigger.WaitAsync();

            False(eventNode.IsCompleted);
            var valueNode = trigger.WaitAsync(state, IsEqualTo42);

            False(trigger.EnsureState(state, IsEqualTo42));
            False(valueNode.IsCompleted);
            trigger.Signal();
            True(eventNode.IsCompletedSuccessfully);
            False(valueNode.IsCompleted);
            state.Value = 14;
            trigger.Signal(state);
            False(valueNode.IsCompleted);
            state.Value = 42;
            True(trigger.EnsureState(state, IsEqualTo42));
            trigger.Signal(state);
            True(valueNode.IsCompletedSuccessfully);