You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
45 lines
968 B
C#
45 lines
968 B
C#
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EpicGames.Core
|
|
{
|
|
/// <summary>
|
|
/// Wrapper to allow awaiting an event being signalled, similar to an AutoResetEvent.
|
|
/// </summary>
|
|
public class AsyncEvent
|
|
{
|
|
/// <summary>
|
|
/// Completion source to wait on
|
|
/// </summary>
|
|
TaskCompletionSource<bool> Source = new TaskCompletionSource<bool>();
|
|
|
|
/// <summary>
|
|
/// Signal the event
|
|
/// </summary>
|
|
public void Set()
|
|
{
|
|
TaskCompletionSource<bool> PrevSource = Interlocked.Exchange(ref Source, new TaskCompletionSource<bool>());
|
|
PrevSource.SetResult(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines if this event is set
|
|
/// </summary>
|
|
/// <returns>True if the event is set</returns>
|
|
public bool IsSet()
|
|
{
|
|
return Source.Task.IsCompleted;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Waits for this event to be set
|
|
/// </summary>
|
|
public Task Task
|
|
{
|
|
get { return Source.Task; }
|
|
}
|
|
}
|
|
}
|