forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskWrapperAsyncResult.cs
More file actions
53 lines (44 loc) · 1.76 KB
/
Copy pathTaskWrapperAsyncResult.cs
File metadata and controls
53 lines (44 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
namespace System.Web.Mvc.Async
{
/// <summary>
/// Wraps a <see cref="Task"/> class, optionally overriding the State object (since the Task Asynchronous Pattern doesn't normally use it).
/// Copied from System.Web.
/// </summary>
internal sealed class TaskWrapperAsyncResult : IAsyncResult
{
private bool? _completedSynchronously;
internal TaskWrapperAsyncResult(Task task, object asyncState, Action cleanupThunk = null)
{
Task = task;
AsyncState = asyncState;
CleanupThunk = cleanupThunk;
}
public object AsyncState { get; private set; }
public WaitHandle AsyncWaitHandle
{
get { return ((IAsyncResult)Task).AsyncWaitHandle; }
}
/// <summary>
/// Cleanup logic to run after Task is finished
/// </summary>
public Action CleanupThunk { get; private set; }
/// <summary>
/// Gets a value indicating whether the asynchronous operation completed synchronously.
/// </summary>
/// <returns>true if the asynchronous operation completed synchronously; otherwise, false.</returns>
public bool CompletedSynchronously
{
get { return _completedSynchronously ?? ((IAsyncResult)Task).CompletedSynchronously; }
internal set { _completedSynchronously = value; }
}
public bool IsCompleted
{
get { return ((IAsyncResult)Task).IsCompleted; }
}
internal Task Task { get; private set; }
}
}