// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; namespace osu.Game.Screens.OnlinePlay { /// /// Utility class to track ongoing online operations' progress. /// Can be used to disable interactivity while waiting for a response from online sources. /// public class OngoingOperationTracker { /// /// Whether there is an online operation in progress. /// public IBindable InProgress => inProgress; private readonly Bindable inProgress = new BindableBool(); private LeasedBindable leasedInProgress; /// /// Begins tracking a new online operation. /// /// An operation has already been started. public void BeginOperation() { if (leasedInProgress != null) throw new InvalidOperationException("Cannot begin operation while another is in progress."); leasedInProgress = inProgress.BeginLease(true); leasedInProgress.Value = true; } /// /// Ends tracking an online operation. /// Does nothing if an operation has not been begun yet. /// public void EndOperation() { leasedInProgress?.Return(); leasedInProgress = null; } } }