using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace OwlCore.WinUI.Threading { /// /// When used as a return type, the continuation happens on the UI thread. /// [AsyncMethodBuilder(typeof(UiTaskMethodBuilder))] public class UiTask { internal TaskCompletionSource Promise { get; } = new TaskCompletionSource(); /// /// Returns a that represents the asynchronous operation. /// public Task AsTask() => Promise.Task; /// public TaskAwaiter GetAwaiter() { return Promise.Task.GetAwaiter(); } /// /// Implicit conversion to a . /// /// The task to convert. public static implicit operator Task(UiTask task) => task.AsTask(); } }