2017-07-20 11:21:28 +02:00
|
|
|
|
using System;
|
2015-05-21 16:09:10 +02:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Scheduling
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2016-09-23 16:42:42 +02:00
|
|
|
|
/// Wraps a <see cref="Task"/> within an object that gives access to its GetAwaiter method and Status
|
2015-05-21 16:09:10 +02:00
|
|
|
|
/// property while ensuring that it cannot be modified in any way.
|
|
|
|
|
|
/// </summary>
|
2016-09-23 16:42:42 +02:00
|
|
|
|
public class ThreadingTaskImmutable
|
2015-05-21 16:09:10 +02:00
|
|
|
|
{
|
|
|
|
|
|
private readonly Task _task;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="ThreadingTaskImmutable"/> class with a Task.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="task">The task.</param>
|
|
|
|
|
|
public ThreadingTaskImmutable(Task task)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (task == null)
|
|
|
|
|
|
throw new ArgumentNullException("task");
|
|
|
|
|
|
_task = task;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets an awaiter used to await the task.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>An awaiter instance.</returns>
|
|
|
|
|
|
public TaskAwaiter GetAwaiter()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _task.GetAwaiter();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the TaskStatus of the task.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>The current TaskStatus of the task.</returns>
|
|
|
|
|
|
public TaskStatus Status
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _task.Status; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|