Files
UnrealEngineUWP/Engine/Source/Programs/Shared/EpicGames.Core/CancellationTask.cs
Joe Kirchoff 2bc7227518 UnrealBuildTool: Clean up some intellisense suggestions, format documents, remove and sort usings, etc.
#rb trivial
#rnx

[CL 17059447 by Joe Kirchoff in ue5-main branch]
2021-08-04 16:49:28 -04:00

51 lines
1.1 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace EpicGames.Core
{
/// <summary>
/// Wrapper class to create a waitable task out of a cancellation token
/// </summary>
public class CancellationTask : IDisposable
{
/// <summary>
/// Completion source for the task
/// </summary>
readonly TaskCompletionSource<bool> CompletionSource;
/// <summary>
/// Registration handle with the cancellation token
/// </summary>
readonly CancellationTokenRegistration Registration;
/// <summary>
/// Constructor
/// </summary>
/// <param name="Token">The cancellation token to register with</param>
public CancellationTask(CancellationToken Token)
{
CompletionSource = new TaskCompletionSource<bool>();
Registration = Token.Register(() => CompletionSource.TrySetResult(true));
}
/// <summary>
/// The task that can be waited on
/// </summary>
public Task Task
{
get { return CompletionSource.Task; }
}
/// <summary>
/// Dispose of any allocated resources
/// </summary>
public void Dispose()
{
Registration.Dispose();
}
}
}