< Summary

Information
Class: LeetCode.Concurrency.PrintInOrder.PrintInOrderThreadSleep
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Concurrency\PrintInOrder\PrintInOrderThreadSleep.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 49
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
First(...)100%11100%
Second(...)100%22100%
Third(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Concurrency\PrintInOrder\PrintInOrderThreadSleep.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Concurrency.PrintInOrder;
 13
 14/// <inheritdoc />
 15public class PrintInOrderThreadSleep : IPrintInOrder
 16{
 17    private const int ThreadTimeoutMs = 10;
 18    private bool _isFirstPrinted;
 19    private bool _isSecondPrinted;
 20
 21    public void First(Action printFirst)
 322    {
 323        printFirst.Invoke();
 24
 325        _isFirstPrinted = true;
 326    }
 27
 28    public void Second(Action printSecond)
 329    {
 430        while (!_isFirstPrinted)
 131        {
 132            Thread.Sleep(ThreadTimeoutMs);
 133        }
 34
 335        printSecond.Invoke();
 36
 337        _isSecondPrinted = true;
 338    }
 39
 40    public void Third(Action printThird)
 341    {
 642        while (!_isSecondPrinted)
 343        {
 344            Thread.Sleep(ThreadTimeoutMs);
 345        }
 46
 347        printThird.Invoke();
 348    }
 49}