2019-05-19 23:14:47 +08:00
|
|
|
|
#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
|
|
|
|
|
|
2020-04-18 04:07:59 +08:00
|
|
|
|
using System;
|
2019-05-19 23:14:47 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-04-18 04:07:59 +08:00
|
|
|
|
using UniRx.Async.Internal;
|
2019-05-19 23:14:47 +08:00
|
|
|
|
|
|
|
|
|
namespace UniRx.Async.CompilerServices
|
|
|
|
|
{
|
2020-04-18 04:07:59 +08:00
|
|
|
|
// TODO: Remove it.
|
2019-05-19 23:14:47 +08:00
|
|
|
|
internal class MoveNextRunner<TStateMachine>
|
|
|
|
|
where TStateMachine : IAsyncStateMachine
|
|
|
|
|
{
|
|
|
|
|
public TStateMachine StateMachine;
|
|
|
|
|
|
|
|
|
|
[DebuggerHidden]
|
|
|
|
|
public void Run()
|
|
|
|
|
{
|
|
|
|
|
StateMachine.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-18 04:07:59 +08:00
|
|
|
|
|
|
|
|
|
internal interface IMoveNextRunner
|
|
|
|
|
{
|
|
|
|
|
Action CallMoveNext { get; }
|
|
|
|
|
void Return();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class MoveNextRunner2<TStateMachine> : IMoveNextRunner, IPromisePoolItem
|
|
|
|
|
where TStateMachine : IAsyncStateMachine
|
|
|
|
|
{
|
|
|
|
|
static PromisePool<MoveNextRunner2<TStateMachine>> pool = new PromisePool<MoveNextRunner2<TStateMachine>>();
|
|
|
|
|
|
|
|
|
|
TStateMachine stateMachine;
|
|
|
|
|
internal readonly Action callMoveNext;
|
|
|
|
|
|
|
|
|
|
public Action CallMoveNext => callMoveNext;
|
|
|
|
|
|
|
|
|
|
MoveNextRunner2()
|
|
|
|
|
{
|
|
|
|
|
callMoveNext = MoveNext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MoveNextRunner2<TStateMachine> Create(ref TStateMachine stateMachine)
|
|
|
|
|
{
|
|
|
|
|
var result = pool.TryRent() ?? new MoveNextRunner2<TStateMachine>();
|
|
|
|
|
result.stateMachine = stateMachine;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DebuggerHidden]
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
void MoveNext()
|
|
|
|
|
{
|
|
|
|
|
stateMachine.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Return()
|
|
|
|
|
{
|
|
|
|
|
pool.TryReturn(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IPromisePoolItem.Reset()
|
|
|
|
|
{
|
|
|
|
|
stateMachine = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-19 23:14:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|