1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00

Adjust operation tracker implementation

This commit is contained in:
Bartłomiej Dach 2020-12-29 07:54:27 +01:00
parent 9ff2140232
commit f59ba799d3

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
namespace osu.Game.Screens.OnlinePlay namespace osu.Game.Screens.OnlinePlay
@ -24,21 +25,26 @@ namespace osu.Game.Screens.OnlinePlay
/// <summary> /// <summary>
/// Begins tracking a new online operation. /// Begins tracking a new online operation.
/// </summary> /// </summary>
/// <returns>
/// An <see cref="IDisposable"/> that will automatically mark the operation as ended on disposal.
/// </returns>
/// <exception cref="InvalidOperationException">An operation has already been started.</exception> /// <exception cref="InvalidOperationException">An operation has already been started.</exception>
public void BeginOperation() public IDisposable BeginOperation()
{ {
if (leasedInProgress != null) if (leasedInProgress != null)
throw new InvalidOperationException("Cannot begin operation while another is in progress."); throw new InvalidOperationException("Cannot begin operation while another is in progress.");
leasedInProgress = inProgress.BeginLease(true); leasedInProgress = inProgress.BeginLease(true);
leasedInProgress.Value = true; leasedInProgress.Value = true;
return new InvokeOnDisposal(endOperation);
} }
/// <summary> /// <summary>
/// Ends tracking an online operation. /// Ends tracking an online operation.
/// Does nothing if an operation has not been begun yet. /// Does nothing if an operation has not been begun yet.
/// </summary> /// </summary>
public void EndOperation() private void endOperation()
{ {
leasedInProgress?.Return(); leasedInProgress?.Return();
leasedInProgress = null; leasedInProgress = null;