-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathClientTask.cs
50 lines (40 loc) · 1.44 KB
/
ClientTask.cs
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
using System;
using System.Runtime.CompilerServices;
using Verse;
namespace Multiplayer.Client.Util;
[AsyncMethodBuilder(typeof(ClientTaskMethodBuilder))]
public struct ClientTask : INotifyCompletion
{
public bool IsCompleted => false;
public void GetResult(){}
public void OnCompleted(Action continuation){}
public ClientTask GetAwaiter() => this;
}
public struct ClientTaskMethodBuilder
{
public static ClientTaskMethodBuilder Create() => new();
public void Start<TStateMachine>(ref TStateMachine stateMachine)
where TStateMachine : IAsyncStateMachine =>
stateMachine.MoveNext();
public void SetStateMachine(IAsyncStateMachine stateMachine) { }
public void SetException(Exception exception)
{
Log.Error($"Multiplayer ClientTask exception: {exception}");
}
public void SetResult(){}
public void AwaitOnCompleted<TAwaiter, TStateMachine>(
ref TAwaiter awaiter, ref TStateMachine stateMachine)
where TAwaiter : INotifyCompletion
where TStateMachine : IAsyncStateMachine
{
awaiter.OnCompleted(stateMachine.MoveNext);
}
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(
ref TAwaiter awaiter, ref TStateMachine stateMachine)
where TAwaiter : ICriticalNotifyCompletion
where TStateMachine : IAsyncStateMachine
{
awaiter.UnsafeOnCompleted(stateMachine.MoveNext);
}
public ClientTask Task { get; }
}