IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
AwaitableCompletionHandler.cs
Go to the documentation of this file.
1using System;
3using System.Threading.Tasks;
4
6{
7
11 public class AwaitableCompletionHandler : AwaitableCompletionHandler<object>
12 {
13
17 public new Task Task => base.Task;
18
22 public new TaskAwaiter GetAwaiter() => Task.GetAwaiter();
23
24 }
25
31 {
32
33
34
35 }
36
41 public class AwaitableCompletionHandler<V, A> : CompletionHandler
42 {
43
44 readonly TaskCompletionSource<V> _source = new TaskCompletionSource<V>();
45 A? _attachment;
46
50 public A? Attachment => _attachment;
51
55 public Task<V> Task => _source.Task;
56
60 public TaskAwaiter<V> GetAwaiter() => Task.GetAwaiter();
61
67 void CompletionHandler.completed(object result, object attachment)
68 {
69 _attachment = (A)attachment;
70 _source.SetResult((V)result);
71 }
72
78 void CompletionHandler.failed(Exception exc, object attachment)
79 {
80 _attachment = (A)attachment;
81 _source.SetException(exc);
82 }
83
84 }
85
86}
An awaitable implementation of a CompletionHandler.
A? Attachment
Gets the attachment which is set after the handler completes.
new Task Task
Gets the task that can be awaited.
new TaskAwaiter GetAwaiter()
Gets an awaiter used to await this completion handler.
TaskAwaiter< V > GetAwaiter()
Gets an awaiter used to await this completion handler.