1
0
mirror of https://github.com/SineVector241/VoiceCraft-MCBE_Proximity_Chat.git synced 2024-11-12 02:19:17 +00:00
VoiceCraft-MCBE_Proximity_Chat/ATL/Utils/ProgressToken.cs
2024-07-13 11:16:08 +10:00

39 lines
1.0 KiB
C#

using System;
namespace ATL
{
/// <summary>
/// Handle used to signal the progress of a process
/// </summary>
/// <typeparam name="T">Type to use to report progress</typeparam>
public sealed class ProgressToken<T>
{
private readonly bool isAsync;
private readonly IProgress<T> asyncProgress;
private readonly Action<T> syncProgress;
internal bool IsAsync => isAsync;
internal IProgress<T> AsyncProgress => asyncProgress;
internal Action<T> SyncProgress => syncProgress;
internal ProgressToken(IProgress<T> progress)
{
isAsync = true;
asyncProgress = progress;
}
internal ProgressToken(Action<T> progress)
{
isAsync = false;
syncProgress = progress;
}
internal void Report(T value)
{
if (isAsync && asyncProgress != null) asyncProgress.Report(value);
else if (!isAsync && syncProgress != null) syncProgress(value);
}
}
}