mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-19 05:30:12 +00:00
more working
This commit is contained in:
@@ -6,6 +6,11 @@ namespace UniRx.Async.Internal
|
||||
{
|
||||
internal static class StateTuple
|
||||
{
|
||||
public static StateTuple<T1> Create<T1>(T1 item1)
|
||||
{
|
||||
return StatePool<T1>.Create(item1);
|
||||
}
|
||||
|
||||
public static StateTuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
|
||||
{
|
||||
return StatePool<T1, T2>.Create(item1, item2);
|
||||
@@ -17,6 +22,45 @@ namespace UniRx.Async.Internal
|
||||
}
|
||||
}
|
||||
|
||||
internal class StateTuple<T1> : IDisposable
|
||||
{
|
||||
public T1 Item1;
|
||||
|
||||
public void Deconstruct(out T1 item1)
|
||||
{
|
||||
item1 = this.Item1;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
StatePool<T1>.Return(this);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class StatePool<T1>
|
||||
{
|
||||
static readonly ConcurrentQueue<StateTuple<T1>> queue = new ConcurrentQueue<StateTuple<T1>>();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static StateTuple<T1> Create(T1 item1)
|
||||
{
|
||||
if (queue.TryDequeue(out var value))
|
||||
{
|
||||
value.Item1 = item1;
|
||||
return value;
|
||||
}
|
||||
|
||||
return new StateTuple<T1> { Item1 = item1 };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Return(StateTuple<T1> tuple)
|
||||
{
|
||||
tuple.Item1 = default;
|
||||
queue.Enqueue(tuple);
|
||||
}
|
||||
}
|
||||
|
||||
internal class StateTuple<T1, T2> : IDisposable
|
||||
{
|
||||
public T1 Item1;
|
||||
|
||||
Reference in New Issue
Block a user