mirror of https://github.com/Cysharp/UniTask
107 lines
2.9 KiB
C#
107 lines
2.9 KiB
C#
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
|
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Security;
|
|
|
|
namespace UniRx.Async.CompilerServices
|
|
{
|
|
public struct AsyncUniTaskVoidMethodBuilder
|
|
{
|
|
IMoveNextRunner runner;
|
|
|
|
// 1. Static Create method.
|
|
[DebuggerHidden]
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static AsyncUniTaskVoidMethodBuilder Create()
|
|
{
|
|
return default;
|
|
}
|
|
|
|
// 2. TaskLike Task property(void)
|
|
public UniTaskVoid Task
|
|
{
|
|
[DebuggerHidden]
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
|
|
// 3. SetException
|
|
[DebuggerHidden]
|
|
public void SetException(Exception exception)
|
|
{
|
|
// runner is finished, return first.
|
|
if (runner != null)
|
|
{
|
|
runner.Return();
|
|
runner = null;
|
|
}
|
|
|
|
UniTaskScheduler.PublishUnobservedTaskException(exception);
|
|
}
|
|
|
|
// 4. SetResult
|
|
[DebuggerHidden]
|
|
public void SetResult()
|
|
{
|
|
// runner is finished, return.
|
|
if (runner != null)
|
|
{
|
|
runner.Return();
|
|
runner = null;
|
|
}
|
|
}
|
|
|
|
// 5. AwaitOnCompleted
|
|
[DebuggerHidden]
|
|
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
|
|
where TAwaiter : INotifyCompletion
|
|
where TStateMachine : IAsyncStateMachine
|
|
{
|
|
if (runner == null)
|
|
{
|
|
runner = MoveNextRunner2<TStateMachine>.Create(ref stateMachine);
|
|
}
|
|
|
|
awaiter.OnCompleted(runner.CallMoveNext);
|
|
}
|
|
|
|
// 6. AwaitUnsafeOnCompleted
|
|
[DebuggerHidden]
|
|
[SecuritySafeCritical]
|
|
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine)
|
|
where TAwaiter : ICriticalNotifyCompletion
|
|
where TStateMachine : IAsyncStateMachine
|
|
{
|
|
if (runner == null)
|
|
{
|
|
runner = MoveNextRunner2<TStateMachine>.Create(ref stateMachine);
|
|
}
|
|
|
|
awaiter.OnCompleted(runner.CallMoveNext);
|
|
}
|
|
|
|
// 7. Start
|
|
[DebuggerHidden]
|
|
public void Start<TStateMachine>(ref TStateMachine stateMachine)
|
|
where TStateMachine : IAsyncStateMachine
|
|
{
|
|
stateMachine.MoveNext();
|
|
}
|
|
|
|
// 8. SetStateMachine
|
|
[DebuggerHidden]
|
|
public void SetStateMachine(IAsyncStateMachine stateMachine)
|
|
{
|
|
// don't use boxed stateMachine.
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif |