Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TaskWrapperAsyncResult.cs « Async « System.Web.Mvc « src - github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9d31a94b0fb4061d276e4b57ade396a4a51f769 (plain)
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
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
    {
        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; }

        public bool CompletedSynchronously
        {
            get { return ((IAsyncResult)Task).CompletedSynchronously; }
        }

        public bool IsCompleted
        {
            get { return ((IAsyncResult)Task).IsCompleted; }
        }

        internal Task Task { get; private set; }
    }
}