Exemple #1
0
        public static async Task SinglePhaseAsyncBarrierExampleAsync()
        {
            var spb = new SinglePhaseAsyncBarrier(3);

            var t1 = Task.Run(async() =>
            {
                Thread.Sleep(1_000);
                Console.WriteLine("Task A Added");
                await spb.SignalAndWaitAsync().ConfigureAwait(false);
                Console.WriteLine("A Done");
            });

            var t2 = Task.Run(async() =>
            {
                Thread.Sleep(2_000);
                Console.WriteLine("Task B Added");
                await spb.SignalAndWaitAsync().ConfigureAwait(false);
                Console.WriteLine("B Done");
            });

            var t3 = Task.Run(async() =>
            {
                Thread.Sleep(3_000);
                Console.WriteLine("Task C Added");
                await spb.SignalAndWaitAsync().ConfigureAwait(false);
                Console.WriteLine("C Done");
            });

            await Task.WhenAll(t1, t2, t3).ConfigureAwait(false);
        }
        public void SinglePhaseAsyncShouldRetornFinishedInAllSignal()
        {
            //Arrange
            var participantCount = 2;
            var barrier          = new SinglePhaseAsyncBarrier(participantCount);

            // Act
            var t1 = barrier.SignalAndWaitAsync();
            var t2 = barrier.SignalAndWaitAsync();

            // Assert
            t1.IsCompleted.Should().BeTrue();
            t2.IsCompleted.Should().BeTrue();
        }
        public void SinglePhaseAsyncShouldRetornNotFinishedInNotAllSignal()
        {
            //Arrange
            var participantCount = 2;
            var barrier          = new SinglePhaseAsyncBarrier(participantCount);

            // Act
            var t = barrier.SignalAndWaitAsync();

            // Assert
            t.IsCompleted.Should().BeFalse();
        }
        public void SinglePhaseAsyncShouldFinishedImmediateWithSingleParticipant()
        {
            //Arrange
            var participantCount = 1;
            var barrier          = new SinglePhaseAsyncBarrier(participantCount);

            // Act
            var t = barrier.SignalAndWaitAsync();

            // Assert
            t.IsCompleted.Should().BeTrue();
        }