mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
125 lines
3.7 KiB
C#
125 lines
3.7 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Security;
|
|
|
|
namespace ET
|
|
{
|
|
public struct ETAsyncTaskMethodBuilder
|
|
{
|
|
private ETTask tcs;
|
|
|
|
// 1. Static Create method.
|
|
[DebuggerHidden]
|
|
public static ETAsyncTaskMethodBuilder Create()
|
|
{
|
|
ETAsyncTaskMethodBuilder builder = new ETAsyncTaskMethodBuilder() { tcs = ETTask.Create(true) };
|
|
return builder;
|
|
}
|
|
|
|
// 2. TaskLike Task property.
|
|
[DebuggerHidden]
|
|
public ETTask Task => this.tcs;
|
|
|
|
// 3. SetException
|
|
[DebuggerHidden]
|
|
public void SetException(Exception exception)
|
|
{
|
|
this.tcs.SetException(exception);
|
|
}
|
|
|
|
// 4. SetResult
|
|
[DebuggerHidden]
|
|
public void SetResult()
|
|
{
|
|
this.tcs.SetResult();
|
|
}
|
|
|
|
// 5. AwaitOnCompleted
|
|
[DebuggerHidden]
|
|
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
|
|
{
|
|
awaiter.OnCompleted(stateMachine.MoveNext);
|
|
}
|
|
|
|
// 6. AwaitUnsafeOnCompleted
|
|
[DebuggerHidden]
|
|
[SecuritySafeCritical]
|
|
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
|
|
{
|
|
awaiter.OnCompleted(stateMachine.MoveNext);
|
|
}
|
|
|
|
// 7. Start
|
|
[DebuggerHidden]
|
|
public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
|
|
{
|
|
stateMachine.MoveNext();
|
|
}
|
|
|
|
// 8. SetStateMachine
|
|
[DebuggerHidden]
|
|
public void SetStateMachine(IAsyncStateMachine stateMachine)
|
|
{
|
|
}
|
|
}
|
|
|
|
public struct ETAsyncTaskMethodBuilder<T>
|
|
{
|
|
private ETTask<T> tcs;
|
|
|
|
// 1. Static Create method.
|
|
[DebuggerHidden]
|
|
public static ETAsyncTaskMethodBuilder<T> Create()
|
|
{
|
|
ETAsyncTaskMethodBuilder<T> builder = new ETAsyncTaskMethodBuilder<T>() { tcs = ETTask<T>.Create(true) };
|
|
return builder;
|
|
}
|
|
|
|
// 2. TaskLike Task property.
|
|
[DebuggerHidden]
|
|
public ETTask<T> Task => this.tcs;
|
|
|
|
// 3. SetException
|
|
[DebuggerHidden]
|
|
public void SetException(Exception exception)
|
|
{
|
|
this.tcs.SetException(exception);
|
|
}
|
|
|
|
// 4. SetResult
|
|
[DebuggerHidden]
|
|
public void SetResult(T ret)
|
|
{
|
|
this.tcs.SetResult(ret);
|
|
}
|
|
|
|
// 5. AwaitOnCompleted
|
|
[DebuggerHidden]
|
|
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
|
|
{
|
|
awaiter.OnCompleted(stateMachine.MoveNext);
|
|
}
|
|
|
|
// 6. AwaitUnsafeOnCompleted
|
|
[DebuggerHidden]
|
|
[SecuritySafeCritical]
|
|
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
|
|
{
|
|
awaiter.OnCompleted(stateMachine.MoveNext);
|
|
}
|
|
|
|
// 7. Start
|
|
[DebuggerHidden]
|
|
public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
|
|
{
|
|
stateMachine.MoveNext();
|
|
}
|
|
|
|
// 8. SetStateMachine
|
|
[DebuggerHidden]
|
|
public void SetStateMachine(IAsyncStateMachine stateMachine)
|
|
{
|
|
}
|
|
}
|
|
} |