File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Runtime . CompilerServices ;
2
3
using System . Threading ;
3
4
using System . Threading . Tasks ;
4
5
using JetBrains . Annotations ;
@@ -121,5 +122,27 @@ public static Task<T> AsTask<T>(this IRdTask<T> task)
121
122
} ) ;
122
123
return tcs . Task ;
123
124
}
125
+
126
+ [ PublicAPI ]
127
+ public static RdTaskAwaiter < T > GetAwaiter < T > ( this IRdTask < T > task ) => new ( task . Result ) ;
128
+
129
+ public readonly struct RdTaskAwaiter < T > : INotifyCompletion
130
+ {
131
+ private readonly IReadonlyProperty < RdTaskResult < T > > myResult ;
132
+
133
+ internal RdTaskAwaiter ( IReadonlyProperty < RdTaskResult < T > > result )
134
+ {
135
+ myResult = result ;
136
+ }
137
+
138
+ public bool IsCompleted => myResult . Maybe . HasValue ;
139
+
140
+ public T GetResult ( ) => myResult . Value . Unwrap ( ) ;
141
+
142
+ public void OnCompleted ( Action continuation )
143
+ {
144
+ myResult . Change . AdviseOnce ( Lifetime . Eternal , _ => continuation ( ) ) ;
145
+ }
146
+ }
124
147
}
125
148
}
Original file line number Diff line number Diff line change @@ -20,7 +20,24 @@ protected override IScheduler CreateScheduler(bool isServer)
20
20
}
21
21
22
22
[ Test ]
23
- public void BindableRdCallListTest ( )
23
+ public void BindableRdCallListUseSystemTaskTest ( )
24
+ {
25
+ BindableRdCallListTest ( TaskKind . System ) ;
26
+ }
27
+
28
+ [ Test ]
29
+ public void BindableRdCallListUseRdTaskTest ( )
30
+ {
31
+ BindableRdCallListTest ( TaskKind . Rd ) ;
32
+ }
33
+
34
+ private enum TaskKind
35
+ {
36
+ System ,
37
+ Rd ,
38
+ }
39
+
40
+ private void BindableRdCallListTest ( TaskKind taskKind )
24
41
{
25
42
ClientWire . AutoTransmitMode = true ;
26
43
ServerWire . AutoTransmitMode = true ;
@@ -52,7 +69,12 @@ public void BindableRdCallListTest()
52
69
{
53
70
BindToClient ( lifetime , callsite , entity_id ) ;
54
71
55
- var list = await callsite . Start ( lifetime , Unit . Instance ) . AsTask ( ) ;
72
+ var list = taskKind switch
73
+ {
74
+ TaskKind . System => await callsite . Start ( lifetime , Unit . Instance ) . AsTask ( ) ,
75
+ TaskKind . Rd => await callsite . Start ( lifetime , Unit . Instance ) ,
76
+ _ => throw new ArgumentOutOfRangeException ( nameof ( taskKind ) , taskKind , null )
77
+ } ;
56
78
var count = 0 ;
57
79
58
80
list . View ( lifetime , ( lt , index , value ) =>
You can’t perform that action at this time.
0 commit comments