回答編集履歴
1
コードの更新
test
CHANGED
@@ -32,10 +32,14 @@
|
|
32
32
|
|
33
33
|
お節介ですが、ちょうど少し前に似たような問題に適用できるスケジューラーの汎用実装を作ったものがあったので、もしよろしければこちらをお使いください。(100行くらいあるけど回答欄に貼ってもいいんですかね……?)
|
34
34
|
|
35
|
+
|
36
|
+
|
35
|
-
|
37
|
+
(12/13 コードを更新)
|
36
38
|
|
37
39
|
```csharp
|
38
40
|
|
41
|
+
|
42
|
+
|
39
43
|
public class ActionQueueScheduler
|
40
44
|
|
41
45
|
{
|
@@ -142,7 +146,7 @@
|
|
142
146
|
|
143
147
|
=> this.Interrupt(async () => { await action(); return default(object); });
|
144
148
|
|
145
|
-
|
149
|
+
|
146
150
|
|
147
151
|
public Task<T> Interrupt<T>(Func<Task<T>> action)
|
148
152
|
|
@@ -190,7 +194,7 @@
|
|
190
194
|
|
191
195
|
}
|
192
196
|
|
193
|
-
return Task.
|
197
|
+
return Task.FromResult(default(object));
|
194
198
|
|
195
199
|
}
|
196
200
|
|
@@ -232,17 +236,17 @@
|
|
232
236
|
|
233
237
|
{
|
234
238
|
|
239
|
+
var action = default(Func<Task>);
|
240
|
+
|
235
241
|
while (true)
|
236
242
|
|
237
243
|
{
|
238
244
|
|
239
245
|
if (this.immediate != null)
|
240
246
|
|
241
|
-
await
|
247
|
+
await Interlocked.Exchange(ref this.immediate, null).Invoke().ConfigureAwait(false);
|
242
|
-
|
243
|
-
|
248
|
+
|
244
|
-
|
245
|
-
else if (this.queue.TryDequeue(out
|
249
|
+
else if (this.queue.TryDequeue(out action))
|
246
250
|
|
247
251
|
await action().ConfigureAwait(false);
|
248
252
|
|