// Copyright Epic Games, Inc. All Rights Reserved.
using System.Threading;
using System.Threading.Tasks;
namespace EpicGames.Core
{
///
/// Wrapper to allow awaiting an event being signalled, similar to an AutoResetEvent.
///
public class AsyncEvent
{
///
/// Completion source to wait on
///
TaskCompletionSource Source = new TaskCompletionSource();
///
/// Signal the event
///
public void Set()
{
TaskCompletionSource PrevSource = Interlocked.Exchange(ref Source, new TaskCompletionSource());
PrevSource.SetResult(true);
}
///
/// Determines if this event is set
///
/// True if the event is set
public bool IsSet()
{
return Source.Task.IsCompleted;
}
///
/// Waits for this event to be set
///
public Task Task
{
get { return Source.Task; }
}
}
}