Example #1
0
        public static void SignalAndWaitUnconditionally()
        {
            using var trigger = new AsyncTrigger();
            var waitTask = trigger.SignalAndWaitAsync();

            False(waitTask.IsCompleted);
            var waitTask2 = trigger.SignalAndWaitAsync();

            True(waitTask.IsCompletedSuccessfully);
            False(waitTask2.IsCompleted);
            trigger.Signal();
            True(waitTask2.IsCompletedSuccessfully);
        }
        public static void SignalAndWait()
        {
            var state = new State {
                Value = 10
            };

            using var trigger = new AsyncTrigger();
            var waitTask = trigger.SignalAndWaitAsync(state, i => i.Value == 42);

            False(waitTask.IsCompleted);
            Equal(10, state.Value);
            state.Value = 42;
            trigger.Signal(state);
            True(waitTask.IsCompletedSuccessfully);
            Equal(42, state.Value);
        }