mirror of https://github.com/Cysharp/UniTask
more more
parent
fbec6e9a58
commit
082f3e7335
|
@ -0,0 +1,65 @@
|
|||
#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.Threading;
|
||||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
public class AsyncLazy<T>
|
||||
{
|
||||
Func<UniTask<T>> valueFactory;
|
||||
UniTask<T> target;
|
||||
object syncLock;
|
||||
bool initialized;
|
||||
|
||||
public AsyncLazy(Func<UniTask<T>> valueFactory)
|
||||
{
|
||||
this.valueFactory = valueFactory;
|
||||
this.target = default;
|
||||
this.syncLock = new object();
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
internal AsyncLazy(UniTask<T> value)
|
||||
{
|
||||
this.valueFactory = null;
|
||||
this.target = value;
|
||||
this.syncLock = null;
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
public UniTask<T> Task => EnsureInitialized();
|
||||
|
||||
public UniTask<T>.Awaiter GetAwaiter() => EnsureInitialized().GetAwaiter();
|
||||
|
||||
UniTask<T> EnsureInitialized()
|
||||
{
|
||||
if (Volatile.Read(ref initialized))
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
return EnsureInitializedCore();
|
||||
}
|
||||
|
||||
UniTask<T> EnsureInitializedCore()
|
||||
{
|
||||
lock (syncLock)
|
||||
{
|
||||
if (!Volatile.Read(ref initialized))
|
||||
{
|
||||
var f = Interlocked.Exchange(ref valueFactory, null);
|
||||
if (f != null)
|
||||
{
|
||||
target = f().Preserve(); // with preserve(allow multiple await).
|
||||
Volatile.Write(ref initialized, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -17,14 +17,14 @@ namespace UniRx.Async
|
|||
return (UniTask.FromCanceled(cts), default(CancellationTokenRegistration));
|
||||
}
|
||||
|
||||
var promise = new UniTaskCompletionSource<AsyncUnit>();
|
||||
var promise = new UniTaskCompletionSource();
|
||||
return (promise.Task, cts.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise));
|
||||
}
|
||||
|
||||
static void Callback(object state)
|
||||
{
|
||||
var promise = (UniTaskCompletionSource<AsyncUnit>)state;
|
||||
promise.TrySetResult(AsyncUnit.Default);
|
||||
var promise = (UniTaskCompletionSource)state;
|
||||
promise.SetResult();
|
||||
}
|
||||
|
||||
public static CancellationTokenRegistration RegisterWithoutCaptureExecutionContext(this CancellationToken cancellationToken, Action callback)
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace UniRx.Async.CompilerServices
|
|||
void Return();
|
||||
}
|
||||
|
||||
internal class MoveNextRunner<TStateMachine> : IMoveNextRunner, IPromisePoolItem
|
||||
internal sealed class MoveNextRunner<TStateMachine> : IMoveNextRunner, IPromisePoolItem
|
||||
where TStateMachine : IAsyncStateMachine
|
||||
{
|
||||
static PromisePool<MoveNextRunner<TStateMachine>> pool = new PromisePool<MoveNextRunner<TStateMachine>>();
|
||||
|
|
|
@ -13,136 +13,117 @@ namespace UniRx.Async
|
|||
{
|
||||
public static class EnumeratorAsyncExtensions
|
||||
{
|
||||
public static IAwaiter GetAwaiter(this IEnumerator enumerator)
|
||||
public static UniTask.Awaiter GetAwaiter(this IEnumerator enumerator)
|
||||
{
|
||||
var awaiter = new EnumeratorAwaiter(enumerator, CancellationToken.None);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter);
|
||||
}
|
||||
return awaiter;
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, CancellationToken.None, out var token), token).GetAwaiter();
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this IEnumerator enumerator)
|
||||
{
|
||||
var awaiter = new EnumeratorAwaiter(enumerator, CancellationToken.None);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.Update, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, CancellationToken.None, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask ConfigureAwait(this IEnumerator enumerator, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var awaiter = new EnumeratorAwaiter(enumerator, cancellationToken);
|
||||
if (!awaiter.IsCompleted)
|
||||
{
|
||||
PlayerLoopHelper.AddAction(timing, awaiter);
|
||||
}
|
||||
return new UniTask(awaiter);
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, timing, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
class EnumeratorAwaiter : IAwaiter, IPlayerLoopItem
|
||||
class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<EnumeratorPromise> pool = new PromisePool<EnumeratorPromise>();
|
||||
|
||||
IEnumerator innerEnumerator;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
Action continuation;
|
||||
AwaiterStatus status;
|
||||
ExceptionDispatchInfo exception;
|
||||
|
||||
public EnumeratorAwaiter(IEnumerator innerEnumerator, CancellationToken cancellationToken)
|
||||
UniTaskCompletionSourceCore<object> core;
|
||||
|
||||
EnumeratorPromise()
|
||||
{
|
||||
}
|
||||
|
||||
public static IUniTaskSource Create(IEnumerator innerEnumerator, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
return;
|
||||
return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token);
|
||||
}
|
||||
|
||||
this.innerEnumerator = ConsumeEnumerator(innerEnumerator);
|
||||
this.status = AwaiterStatus.Pending;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.continuation = null;
|
||||
var result = pool.TryRent() ?? new EnumeratorPromise();
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 2);
|
||||
result.innerEnumerator = ConsumeEnumerator(innerEnumerator);
|
||||
result.cancellationToken = cancellationToken;
|
||||
|
||||
TaskTracker2.TrackActiveTask(result, 3);
|
||||
|
||||
PlayerLoopHelper.AddAction(timing, result);
|
||||
|
||||
token = result.core.Version;
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
public void GetResult(short token)
|
||||
{
|
||||
switch (status)
|
||||
try
|
||||
{
|
||||
case AwaiterStatus.Succeeded:
|
||||
break;
|
||||
case AwaiterStatus.Pending:
|
||||
Error.ThrowNotYetCompleted();
|
||||
break;
|
||||
case AwaiterStatus.Faulted:
|
||||
exception.Throw();
|
||||
break;
|
||||
case AwaiterStatus.Canceled:
|
||||
Error.ThrowOperationCanceledException();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
TaskTracker2.RemoveTracking(this);
|
||||
core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
{
|
||||
pool.TryReturn(this);
|
||||
}
|
||||
}
|
||||
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
||||
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||
{
|
||||
core.OnCompleted(continuation, state, token);
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
core.SetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
var success = false;
|
||||
try
|
||||
{
|
||||
if (innerEnumerator.MoveNext())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
}
|
||||
|
||||
InvokeContinuation(success ? AwaiterStatus.Succeeded : AwaiterStatus.Faulted);
|
||||
core.SetException(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
||||
// cleanup
|
||||
TaskTracker.RemoveTracking(this);
|
||||
this.continuation = null;
|
||||
this.cancellationToken = CancellationToken.None;
|
||||
this.innerEnumerator = null;
|
||||
|
||||
if (cont != null) cont.Invoke();
|
||||
core.SetResult(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
public void Reset()
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
Error.ThrowWhenContinuationIsAlreadyRegistered(this.continuation);
|
||||
this.continuation = continuation;
|
||||
core.Reset();
|
||||
innerEnumerator = default;
|
||||
cancellationToken = default;
|
||||
continuation = default;
|
||||
exception = default;
|
||||
}
|
||||
|
||||
// Unwrap YieldInstructions
|
||||
|
|
|
@ -6,9 +6,7 @@ using System.Runtime.CompilerServices;
|
|||
|
||||
namespace UniRx.Async
|
||||
{
|
||||
// TODO:rename to UniTaskStatus
|
||||
|
||||
public enum AwaiterStatus
|
||||
public enum UniTaskStatus
|
||||
{
|
||||
/// <summary>The operation has not yet completed.</summary>
|
||||
Pending = 0,
|
||||
|
@ -20,16 +18,14 @@ namespace UniRx.Async
|
|||
Canceled = 3
|
||||
}
|
||||
|
||||
|
||||
|
||||
// similar as IValueTaskSource
|
||||
public interface IUniTaskSource
|
||||
{
|
||||
AwaiterStatus GetStatus(short token);
|
||||
UniTaskStatus GetStatus(short token);
|
||||
void OnCompleted(Action<object> continuation, object state, short token);
|
||||
void GetResult(short token);
|
||||
|
||||
AwaiterStatus UnsafeGetStatus(); // only for debug use.
|
||||
UniTaskStatus UnsafeGetStatus(); // only for debug use.
|
||||
}
|
||||
|
||||
public interface IUniTaskSource<out T> : IUniTaskSource
|
||||
|
@ -37,47 +33,34 @@ namespace UniRx.Async
|
|||
new T GetResult(short token);
|
||||
}
|
||||
|
||||
|
||||
public interface IAwaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
AwaiterStatus Status { get; }
|
||||
bool IsCompleted { get; }
|
||||
void GetResult();
|
||||
}
|
||||
|
||||
public interface IAwaiter<out T> : IAwaiter
|
||||
{
|
||||
new T GetResult();
|
||||
}
|
||||
|
||||
public static class AwaiterStatusExtensions
|
||||
public static class UniTaskStatusExtensions
|
||||
{
|
||||
/// <summary>!= Pending.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsCompleted(this AwaiterStatus status)
|
||||
public static bool IsCompleted(this UniTaskStatus status)
|
||||
{
|
||||
return status != AwaiterStatus.Pending;
|
||||
return status != UniTaskStatus.Pending;
|
||||
}
|
||||
|
||||
/// <summary>== Succeeded.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsCompletedSuccessfully(this AwaiterStatus status)
|
||||
public static bool IsCompletedSuccessfully(this UniTaskStatus status)
|
||||
{
|
||||
return status == AwaiterStatus.Succeeded;
|
||||
return status == UniTaskStatus.Succeeded;
|
||||
}
|
||||
|
||||
/// <summary>== Canceled.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsCanceled(this AwaiterStatus status)
|
||||
public static bool IsCanceled(this UniTaskStatus status)
|
||||
{
|
||||
return status == AwaiterStatus.Canceled;
|
||||
return status == UniTaskStatus.Canceled;
|
||||
}
|
||||
|
||||
/// <summary>== Faulted.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsFaulted(this AwaiterStatus status)
|
||||
public static bool IsFaulted(this UniTaskStatus status)
|
||||
{
|
||||
return status == AwaiterStatus.Faulted;
|
||||
return status == UniTaskStatus.Faulted;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ namespace UniRx.Async.Internal
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus Status
|
||||
public UniTaskStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ namespace UniRx.Async.Internal
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus Status
|
||||
public UniTaskStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -1,395 +0,0 @@
|
|||
#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.ExceptionServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace UniRx.Async.Internal
|
||||
{
|
||||
// public for some types uses it.
|
||||
|
||||
public abstract class ReusablePromise : IAwaiter
|
||||
{
|
||||
ExceptionDispatchInfo exception;
|
||||
object continuation; // Action or Queue<Action>
|
||||
AwaiterStatus status;
|
||||
|
||||
public UniTask Task => new UniTask(this);
|
||||
|
||||
// can override for control 'start/reset' timing.
|
||||
public virtual bool IsCompleted => status.IsCompleted();
|
||||
|
||||
public virtual void GetResult()
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case AwaiterStatus.Succeeded:
|
||||
return;
|
||||
case AwaiterStatus.Faulted:
|
||||
exception.Throw();
|
||||
break;
|
||||
case AwaiterStatus.Canceled:
|
||||
throw new OperationCanceledException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Invalid Status:" + status);
|
||||
}
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
GetResult();
|
||||
}
|
||||
|
||||
public void ResetStatus(bool forceReset)
|
||||
{
|
||||
if (forceReset)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
else if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TrySetCanceled()
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetException(Exception ex)
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Faulted;
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TryInvokeContinuation()
|
||||
{
|
||||
if (continuation == null) return;
|
||||
|
||||
if (continuation is Action act)
|
||||
{
|
||||
continuation = null;
|
||||
act();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reuse Queue(don't null clear)
|
||||
var q = (MinimumQueue<Action>)continuation;
|
||||
var size = q.Count;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
q.Dequeue().Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action action)
|
||||
{
|
||||
UnsafeOnCompleted(action);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action action)
|
||||
{
|
||||
if (continuation == null)
|
||||
{
|
||||
continuation = action;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (continuation is Action act)
|
||||
{
|
||||
var q = new MinimumQueue<Action>(4);
|
||||
q.Enqueue(act);
|
||||
q.Enqueue(action);
|
||||
continuation = q;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
((MinimumQueue<Action>)continuation).Enqueue(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class ReusablePromise<T> : IAwaiter<T>
|
||||
{
|
||||
T result;
|
||||
ExceptionDispatchInfo exception;
|
||||
object continuation; // Action or Queue<Action>
|
||||
AwaiterStatus status;
|
||||
|
||||
public UniTask<T> Task => new UniTask<T>(this);
|
||||
|
||||
// can override for control 'start/reset' timing.
|
||||
public virtual bool IsCompleted => status.IsCompleted();
|
||||
|
||||
protected T RawResult => result;
|
||||
|
||||
protected void ForceSetResult(T result)
|
||||
{
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public virtual T GetResult()
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case AwaiterStatus.Succeeded:
|
||||
return result;
|
||||
case AwaiterStatus.Faulted:
|
||||
exception.Throw();
|
||||
break;
|
||||
case AwaiterStatus.Canceled:
|
||||
throw new OperationCanceledException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Invalid Status:" + status);
|
||||
}
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
GetResult();
|
||||
}
|
||||
|
||||
public void ResetStatus(bool forceReset)
|
||||
{
|
||||
if (forceReset)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
else if (status == AwaiterStatus.Succeeded)
|
||||
{
|
||||
status = AwaiterStatus.Pending;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool TrySetCanceled()
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetException(Exception ex)
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Faulted;
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TrySetResult(T result)
|
||||
{
|
||||
if (status == AwaiterStatus.Pending)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
this.result = result;
|
||||
TryInvokeContinuation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void TryInvokeContinuation()
|
||||
{
|
||||
if (continuation == null) return;
|
||||
|
||||
if (continuation is Action act)
|
||||
{
|
||||
continuation = null;
|
||||
act();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reuse Queue(don't null clear)
|
||||
var q = (MinimumQueue<Action>)continuation;
|
||||
var size = q.Count;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
q.Dequeue().Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action action)
|
||||
{
|
||||
UnsafeOnCompleted(action);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action action)
|
||||
{
|
||||
if (continuation == null)
|
||||
{
|
||||
continuation = action;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (continuation is Action act)
|
||||
{
|
||||
var q = new MinimumQueue<Action>(4);
|
||||
q.Enqueue(act);
|
||||
q.Enqueue(action);
|
||||
continuation = q;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
((MinimumQueue<Action>)continuation).Enqueue(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class PlayerLoopReusablePromiseBase : ReusablePromise, IPlayerLoopItem
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
protected readonly CancellationToken cancellationToken;
|
||||
bool isRunning = false;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
string capturedStackTraceForDebugging;
|
||||
#endif
|
||||
|
||||
public PlayerLoopReusablePromiseBase(PlayerLoopTiming timing, CancellationToken cancellationToken, int skipTrackFrameCountAdditive)
|
||||
{
|
||||
this.timing = timing;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
this.capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(skipTrackFrameCountAdditive + 1); // 1 is self,
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Status == AwaiterStatus.Canceled || Status == AwaiterStatus.Faulted) return true;
|
||||
|
||||
if (!isRunning)
|
||||
{
|
||||
isRunning = true;
|
||||
ResetStatus(false);
|
||||
OnRunningStart();
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.TrackActiveTask(this, capturedStackTraceForDebugging);
|
||||
#endif
|
||||
PlayerLoopHelper.AddAction(timing, this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnRunningStart();
|
||||
|
||||
protected void Complete()
|
||||
{
|
||||
isRunning = false;
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.RemoveTracking(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract bool MoveNext();
|
||||
}
|
||||
|
||||
public abstract class PlayerLoopReusablePromiseBase<T> : ReusablePromise<T>, IPlayerLoopItem
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
protected readonly CancellationToken cancellationToken;
|
||||
bool isRunning = false;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
string capturedStackTraceForDebugging;
|
||||
#endif
|
||||
|
||||
public PlayerLoopReusablePromiseBase(PlayerLoopTiming timing, CancellationToken cancellationToken, int skipTrackFrameCountAdditive)
|
||||
{
|
||||
this.timing = timing;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
this.capturedStackTraceForDebugging = TaskTracker.CaptureStackTrace(skipTrackFrameCountAdditive + 1); // 1 is self,
|
||||
#endif
|
||||
}
|
||||
|
||||
public override bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Status == AwaiterStatus.Canceled || Status == AwaiterStatus.Faulted) return true;
|
||||
|
||||
if (!isRunning)
|
||||
{
|
||||
isRunning = true;
|
||||
ResetStatus(false);
|
||||
OnRunningStart();
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.TrackActiveTask(this, capturedStackTraceForDebugging);
|
||||
#endif
|
||||
PlayerLoopHelper.AddAction(timing, this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnRunningStart();
|
||||
|
||||
protected void Complete()
|
||||
{
|
||||
isRunning = false;
|
||||
#if UNITY_EDITOR
|
||||
TaskTracker.RemoveTracking(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract bool MoveNext();
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a8cfc99b5928c0242919aac2121b02bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace UniRx.Async.Internal
|
||||
{
|
||||
internal static class StateTuple
|
||||
{
|
||||
public static StateTuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
|
||||
{
|
||||
return StatePool<T1, T2>.Create(item1, item2);
|
||||
}
|
||||
}
|
||||
|
||||
internal class StateTuple<T1, T2> : IDisposable
|
||||
{
|
||||
public T1 Item1;
|
||||
public T2 Item2;
|
||||
|
||||
public void Deconstruct(out T1 item1, out T2 item2)
|
||||
{
|
||||
item1 = this.Item1;
|
||||
item2 = this.Item2;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
StatePool<T1, T2>.Return(this);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class StatePool<T1, T2>
|
||||
{
|
||||
static readonly ConcurrentQueue<StateTuple<T1, T2>> queue = new ConcurrentQueue<StateTuple<T1, T2>>();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static StateTuple<T1, T2> Create(T1 item1, T2 item2)
|
||||
{
|
||||
if (queue.TryDequeue(out var value))
|
||||
{
|
||||
value.Item1 = item1;
|
||||
value.Item2 = item2;
|
||||
return value;
|
||||
}
|
||||
|
||||
return new StateTuple<T1, T2> { Item1 = item1, Item2 = item2 };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Return(StateTuple<T1, T2> tuple)
|
||||
{
|
||||
tuple.Item1 = default;
|
||||
tuple.Item2 = default;
|
||||
queue.Enqueue(tuple);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -116,7 +116,7 @@ namespace UniRx.Async.Internal
|
|||
}
|
||||
|
||||
/// <summary>(trackingId, awaiterType, awaiterStatus, createdTime, stackTrace)</summary>
|
||||
public static void ForEachActiveTask(Action<int, string, AwaiterStatus, DateTime, string> action)
|
||||
public static void ForEachActiveTask(Action<int, string, UniTaskStatus, DateTime, string> action)
|
||||
{
|
||||
lock (listPool)
|
||||
{
|
||||
|
@ -233,7 +233,7 @@ namespace UniRx.Async.Internal
|
|||
}
|
||||
|
||||
/// <summary>(trackingId, awaiterType, awaiterStatus, createdTime, stackTrace)</summary>
|
||||
public static void ForEachActiveTask(Action<int, string, AwaiterStatus, DateTime, string> action)
|
||||
public static void ForEachActiveTask(Action<int, string, UniTaskStatus, DateTime, string> action)
|
||||
{
|
||||
lock (listPool)
|
||||
{
|
||||
|
|
|
@ -32,13 +32,13 @@ namespace UniRx.Async.Triggers
|
|||
|
||||
public override T GetResult()
|
||||
{
|
||||
if (Status == AwaiterStatus.Pending) return RawResult;
|
||||
if (Status == UniTaskStatus.Pending) return RawResult;
|
||||
return base.GetResult();
|
||||
}
|
||||
|
||||
public override bool TrySetResult(T result)
|
||||
{
|
||||
if (Status == AwaiterStatus.Pending)
|
||||
if (Status == UniTaskStatus.Pending)
|
||||
{
|
||||
// keep status as Pending.
|
||||
this.ForceSetResult(result);
|
||||
|
@ -50,7 +50,7 @@ namespace UniRx.Async.Triggers
|
|||
|
||||
public override bool TrySetCanceled()
|
||||
{
|
||||
if (Status == AwaiterStatus.Canceled) return false;
|
||||
if (Status == UniTaskStatus.Canceled) return false;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
return base.TrySetCanceled();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace UniRx.Async
|
|||
|
||||
public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
PlayerLoopHelper.Initialize(
|
||||
|
||||
if (delayFrameCount < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Delay does not allow minus delayFrameCount. delayFrameCount:" + delayFrameCount);
|
||||
|
@ -57,7 +59,7 @@ namespace UniRx.Async
|
|||
: new UniTask(DelayPromise.Create(delayTimeSpan, delayTiming, cancellationToken, out token), token);
|
||||
}
|
||||
|
||||
class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
sealed class YieldPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<YieldPromise> pool = new PromisePool<YieldPromise>();
|
||||
|
||||
|
@ -100,12 +102,12 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -134,7 +136,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<DelayFramePromise> pool = new PromisePool<DelayFramePromise>();
|
||||
|
||||
|
@ -181,12 +183,12 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -223,7 +225,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<DelayPromise> pool = new PromisePool<DelayPromise>();
|
||||
|
||||
|
@ -271,12 +273,12 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -313,7 +315,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<DelayIgnoreTimeScalePromise> pool = new PromisePool<DelayIgnoreTimeScalePromise>();
|
||||
|
||||
|
@ -361,12 +363,12 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -404,7 +406,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public struct YieldAwaitable
|
||||
public readonly struct YieldAwaitable
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
|
@ -423,7 +425,7 @@ namespace UniRx.Async
|
|||
return UniTask.Yield(timing, CancellationToken.None);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
public readonly struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
|
|
|
@ -83,12 +83,19 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
// TODO:...
|
||||
|
||||
/// <summary>shorthand of new UniTask[T](Func[UniTask[T]] factory)</summary>
|
||||
public static UniTask<T> Lazy<T>(Func<UniTask<T>> factory)
|
||||
public static UniTask Create(Func<UniTask> factory)
|
||||
{
|
||||
return new UniTask<T>(factory);
|
||||
return factory();
|
||||
}
|
||||
|
||||
public static UniTask<T> Create<T>(Func<UniTask<T>> factory)
|
||||
{
|
||||
return factory();
|
||||
}
|
||||
|
||||
public static AsyncLazy<T> Lazy<T>(Func<UniTask<T>> factory)
|
||||
{
|
||||
return new AsyncLazy<T>(factory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -122,7 +129,6 @@ namespace UniRx.Async
|
|||
|
||||
internal static class CompletedTasks
|
||||
{
|
||||
public static readonly UniTask Completed = new UniTask();
|
||||
public static readonly UniTask<AsyncUnit> AsyncUnit = UniTask.FromResult(UniRx.Async.AsyncUnit.Default);
|
||||
public static readonly UniTask<bool> True = UniTask.FromResult(true);
|
||||
public static readonly UniTask<bool> False = UniTask.FromResult(false);
|
||||
|
|
|
@ -62,12 +62,12 @@ namespace UniRx.Async
|
|||
|
||||
for (int i = 0; i < tasksLength; i++)
|
||||
{
|
||||
if (tasks[i].IsCompleted)
|
||||
if (tasks[i].Status.IsCompleted())
|
||||
{
|
||||
T value = default(T);
|
||||
try
|
||||
{
|
||||
value = tasks[i].Result;
|
||||
value = tasks[i].GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -189,11 +189,11 @@ namespace UniRx.Async
|
|||
|
||||
for (int i = 0; i < tasksLength; i++)
|
||||
{
|
||||
if (tasks[i].IsCompleted)
|
||||
if (tasks[i].Status.IsCompleted())
|
||||
{
|
||||
try
|
||||
{
|
||||
tasks[i].GetResult();
|
||||
tasks[i].GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -39,13 +39,13 @@ namespace UniRx.Async
|
|||
this.token = token;
|
||||
}
|
||||
|
||||
public AwaiterStatus Status
|
||||
public UniTaskStatus Status
|
||||
{
|
||||
[DebuggerHidden]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
if (source == null) return AwaiterStatus.Succeeded;
|
||||
if (source == null) return UniTaskStatus.Succeeded;
|
||||
return source.GetStatus(token);
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ namespace UniRx.Async
|
|||
public UniTask<bool> SuppressCancellationThrow()
|
||||
{
|
||||
var status = Status;
|
||||
if (status == AwaiterStatus.Succeeded) return CompletedTasks.False;
|
||||
if (status == AwaiterStatus.Canceled) return CompletedTasks.True;
|
||||
if (status == UniTaskStatus.Succeeded) return CompletedTasks.False;
|
||||
if (status == UniTaskStatus.Canceled) return CompletedTasks.True;
|
||||
return new UniTask<bool>(new IsCanceledSource(source), token);
|
||||
}
|
||||
|
||||
|
@ -89,20 +89,20 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public static implicit operator UniTask<AsyncUnit>(UniTask task)
|
||||
public UniTask<AsyncUnit> AsAsyncUnitUniTask()
|
||||
{
|
||||
if (task.source == null) return CompletedTasks.AsyncUnit;
|
||||
if (this.source == null) return CompletedTasks.AsyncUnit;
|
||||
|
||||
var status = task.source.GetStatus(task.token);
|
||||
var status = this.source.GetStatus(this.token);
|
||||
if (status.IsCompletedSuccessfully())
|
||||
{
|
||||
return CompletedTasks.AsyncUnit;
|
||||
}
|
||||
|
||||
return new UniTask<AsyncUnit>(new AsyncUnitSource(task.source), task.token);
|
||||
return new UniTask<AsyncUnit>(new AsyncUnitSource(this.source), this.token);
|
||||
}
|
||||
|
||||
class AsyncUnitSource : IUniTaskSource<AsyncUnit>
|
||||
sealed class AsyncUnitSource : IUniTaskSource<AsyncUnit>
|
||||
{
|
||||
readonly IUniTaskSource source;
|
||||
|
||||
|
@ -117,7 +117,7 @@ namespace UniRx.Async
|
|||
return AsyncUnit.Default;
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return source.GetStatus(token);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ namespace UniRx.Async
|
|||
source.OnCompleted(continuation, state, token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return source.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
class IsCanceledSource : IUniTaskSource<bool>
|
||||
sealed class IsCanceledSource : IUniTaskSource<bool>
|
||||
{
|
||||
readonly IUniTaskSource source;
|
||||
|
||||
|
@ -149,7 +149,7 @@ namespace UniRx.Async
|
|||
|
||||
public bool GetResult(short token)
|
||||
{
|
||||
if (source.GetStatus(token) == AwaiterStatus.Canceled)
|
||||
if (source.GetStatus(token) == UniTaskStatus.Canceled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -163,12 +163,12 @@ namespace UniRx.Async
|
|||
GetResult(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return source.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return source.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -179,11 +179,11 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
class MemoizeSource : IUniTaskSource
|
||||
sealed class MemoizeSource : IUniTaskSource
|
||||
{
|
||||
IUniTaskSource source;
|
||||
ExceptionDispatchInfo exception;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
|
||||
public MemoizeSource(IUniTaskSource source)
|
||||
{
|
||||
|
@ -204,18 +204,18 @@ namespace UniRx.Async
|
|||
try
|
||||
{
|
||||
source.GetResult(token);
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
if (ex is OperationCanceledException)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
status = UniTaskStatus.Canceled;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = AwaiterStatus.Faulted;
|
||||
status = UniTaskStatus.Faulted;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
|
@ -248,7 +248,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
|
@ -361,13 +361,13 @@ namespace UniRx.Async
|
|||
this.result = default;
|
||||
}
|
||||
|
||||
public AwaiterStatus Status
|
||||
public UniTaskStatus Status
|
||||
{
|
||||
[DebuggerHidden]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
return (source == null) ? AwaiterStatus.Succeeded : source.GetStatus(token);
|
||||
return (source == null) ? UniTaskStatus.Succeeded : source.GetStatus(token);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,17 +393,17 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public static implicit operator UniTask(UniTask<T> task)
|
||||
public UniTask AsUniTask()
|
||||
{
|
||||
if (task.source == null) return UniTask.CompletedTask;
|
||||
if (this.source == null) return UniTask.CompletedTask;
|
||||
|
||||
var status = task.source.GetStatus(task.token);
|
||||
var status = this.source.GetStatus(this.token);
|
||||
if (status.IsCompletedSuccessfully())
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
return new UniTask(task.source, task.token);
|
||||
return new UniTask(this.source, this.token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -425,7 +425,7 @@ namespace UniRx.Async
|
|||
: "(" + this.source.UnsafeGetStatus() + ")";
|
||||
}
|
||||
|
||||
class IsCanceledSource : IUniTaskSource<(bool, T)>
|
||||
sealed class IsCanceledSource : IUniTaskSource<(bool, T)>
|
||||
{
|
||||
readonly IUniTaskSource<T> source;
|
||||
|
||||
|
@ -440,7 +440,7 @@ namespace UniRx.Async
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (bool, T) GetResult(short token)
|
||||
{
|
||||
if (source.GetStatus(token) == AwaiterStatus.Canceled)
|
||||
if (source.GetStatus(token) == UniTaskStatus.Canceled)
|
||||
{
|
||||
return (true, default);
|
||||
}
|
||||
|
@ -458,14 +458,14 @@ namespace UniRx.Async
|
|||
|
||||
[DebuggerHidden]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return source.GetStatus(token);
|
||||
}
|
||||
|
||||
[DebuggerHidden]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return source.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -478,12 +478,12 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
class MemoizeSource : IUniTaskSource<T>
|
||||
sealed class MemoizeSource : IUniTaskSource<T>
|
||||
{
|
||||
IUniTaskSource<T> source;
|
||||
T result;
|
||||
ExceptionDispatchInfo exception;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
|
||||
public MemoizeSource(IUniTaskSource<T> source)
|
||||
{
|
||||
|
@ -505,7 +505,7 @@ namespace UniRx.Async
|
|||
try
|
||||
{
|
||||
result = source.GetResult(token);
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -513,11 +513,11 @@ namespace UniRx.Async
|
|||
exception = ExceptionDispatchInfo.Capture(ex);
|
||||
if (ex is OperationCanceledException)
|
||||
{
|
||||
status = AwaiterStatus.Canceled;
|
||||
status = UniTaskStatus.Canceled;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = AwaiterStatus.Faulted;
|
||||
status = UniTaskStatus.Faulted;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ namespace UniRx.Async
|
|||
GetResult(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
|
@ -555,7 +555,7 @@ namespace UniRx.Async
|
|||
}
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace UniRx.Async
|
|||
// Struct Size: TResult + (8 + 2 + 1 + 1 + 8 + 8)
|
||||
|
||||
TResult result;
|
||||
object error; // Exception or OperationCanceledException
|
||||
object error; // ExceptionDispatchInfo or OperationCanceledException
|
||||
short version;
|
||||
bool completed;
|
||||
bool hasUnhandledError;
|
||||
|
@ -119,23 +119,23 @@ namespace UniRx.Async
|
|||
/// <summary>Gets the status of the operation.</summary>
|
||||
/// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
ValidateToken(token);
|
||||
return (continuation == null || !completed) ? AwaiterStatus.Pending
|
||||
: (error == null) ? AwaiterStatus.Succeeded
|
||||
: (error is OperationCanceledException) ? AwaiterStatus.Canceled
|
||||
: AwaiterStatus.Faulted;
|
||||
return (continuation == null || !completed) ? UniTaskStatus.Pending
|
||||
: (error == null) ? UniTaskStatus.Succeeded
|
||||
: (error is OperationCanceledException) ? UniTaskStatus.Canceled
|
||||
: UniTaskStatus.Faulted;
|
||||
}
|
||||
|
||||
/// <summary>Gets the status of the operation without token validation.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return (continuation == null || !completed) ? AwaiterStatus.Pending
|
||||
: (error == null) ? AwaiterStatus.Succeeded
|
||||
: (error is OperationCanceledException) ? AwaiterStatus.Canceled
|
||||
: AwaiterStatus.Faulted;
|
||||
return (continuation == null || !completed) ? UniTaskStatus.Pending
|
||||
: (error == null) ? UniTaskStatus.Succeeded
|
||||
: (error is OperationCanceledException) ? UniTaskStatus.Canceled
|
||||
: UniTaskStatus.Faulted;
|
||||
}
|
||||
|
||||
/// <summary>Gets the result of the operation.</summary>
|
||||
|
@ -296,12 +296,12 @@ namespace UniRx.Async
|
|||
core.GetResult(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -396,12 +396,12 @@ namespace UniRx.Async
|
|||
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -487,12 +487,12 @@ namespace UniRx.Async
|
|||
GetResult(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -591,12 +591,12 @@ namespace UniRx.Async
|
|||
GetResult(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
|
|
@ -12,24 +12,6 @@ namespace UniRx.Async
|
|||
{
|
||||
public static partial class UniTaskExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert UniTask -> UniTask[AsyncUnit].
|
||||
/// </summary>
|
||||
public static UniTask<AsyncUnit> AsAsyncUnitUniTask(this UniTask task)
|
||||
{
|
||||
// use implicit conversion
|
||||
return task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert UniTask[T] -> UniTask.
|
||||
/// </summary>
|
||||
public static UniTask AsUniTask<T>(this UniTask<T> task)
|
||||
{
|
||||
// use implicit conversion
|
||||
return task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert Task[T] -> UniTask[T].
|
||||
/// </summary>
|
||||
|
@ -112,7 +94,9 @@ namespace UniRx.Async
|
|||
|
||||
awaiter.SourceOnCompleted(state =>
|
||||
{
|
||||
var (inTcs, inAwaiter) = ((TaskCompletionSource<T>, UniTask<T>.Awaiter))state;
|
||||
using (var tuple = (StateTuple<TaskCompletionSource<T>, UniTask<T>.Awaiter>)state)
|
||||
{
|
||||
var (inTcs, inAwaiter) = tuple;
|
||||
try
|
||||
{
|
||||
var result = inAwaiter.GetResult();
|
||||
|
@ -122,7 +106,8 @@ namespace UniRx.Async
|
|||
{
|
||||
inTcs.SetException(ex);
|
||||
}
|
||||
}, (tcs, awaiter));
|
||||
}
|
||||
}, StateTuple.Create(tcs, awaiter));
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
@ -154,7 +139,9 @@ namespace UniRx.Async
|
|||
|
||||
awaiter.SourceOnCompleted(state =>
|
||||
{
|
||||
var (inTcs, inAwaiter) = ((TaskCompletionSource<object>, UniTask.Awaiter))state;
|
||||
using (var tuple = (StateTuple<TaskCompletionSource<object>, UniTask.Awaiter>)state)
|
||||
{
|
||||
var (inTcs, inAwaiter) = tuple;
|
||||
try
|
||||
{
|
||||
inAwaiter.GetResult();
|
||||
|
@ -164,7 +151,8 @@ namespace UniRx.Async
|
|||
{
|
||||
inTcs.SetException(ex);
|
||||
}
|
||||
}, (tcs, awaiter));
|
||||
}
|
||||
}, StateTuple.Create(tcs, awaiter));
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
@ -196,7 +184,7 @@ namespace UniRx.Async
|
|||
// left, right both suppress operation canceled exception.
|
||||
|
||||
var delayCancellationTokenSource = new CancellationTokenSource();
|
||||
var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow();
|
||||
var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow();
|
||||
|
||||
var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask);
|
||||
|
||||
|
@ -242,7 +230,7 @@ namespace UniRx.Async
|
|||
// left, right both suppress operation canceled exception.
|
||||
|
||||
var delayCancellationTokenSource = new CancellationTokenSource();
|
||||
var timeoutTask = (UniTask)UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow();
|
||||
var timeoutTask = UniTask.Delay(timeout, ignoreTimeScale, timeoutCheckTiming).SuppressCancellationThrow();
|
||||
|
||||
var (hasValue, value) = await UniTask.WhenAny(task.SuppressCancellationThrow(), timeoutTask);
|
||||
|
||||
|
|
|
@ -52,20 +52,20 @@ namespace UniRx.Async
|
|||
{
|
||||
JobHandle jobHandle;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
|
||||
public JobHandleAwaiter(JobHandle jobHandle, CancellationToken cancellationToken, int skipFrame = 2)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: jobHandle.IsCompleted ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: jobHandle.IsCompleted ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
this.jobHandle = jobHandle;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.status = AwaiterStatus.Pending;
|
||||
this.status = UniTaskStatus.Pending;
|
||||
this.continuation = null;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, skipFrame);
|
||||
|
@ -73,15 +73,15 @@ namespace UniRx.Async
|
|||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
if (status == UniTaskStatus.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
else if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -95,21 +95,21 @@ namespace UniRx.Async
|
|||
{
|
||||
// Call jobHandle.Complete after finished.
|
||||
PlayerLoopHelper.AddAction(PlayerLoopTiming.EarlyUpdate, new JobHandleAwaiter(jobHandle, CancellationToken.None, 1));
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (jobHandle.IsCompleted)
|
||||
{
|
||||
jobHandle.Complete();
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
|
|
@ -187,28 +187,28 @@ namespace UniRx.Async
|
|||
{
|
||||
AsyncOperation asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
|
||||
public AsyncOperationAwaiter(AsyncOperation asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return;
|
||||
if (status == UniTaskStatus.Succeeded) return;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
if (status == UniTaskStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -246,14 +246,14 @@ namespace UniRx.Async
|
|||
AsyncOperation asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
|
||||
public AsyncOperationConfiguredAwaiter(AsyncOperation asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: asyncOperation.isDone ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
|
@ -266,15 +266,15 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
if (status == UniTaskStatus.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
else if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ namespace UniRx.Async
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -297,14 +297,14 @@ namespace UniRx.Async
|
|||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
@ -335,30 +335,30 @@ namespace UniRx.Async
|
|||
{
|
||||
ResourceRequest asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public ResourceRequestAwaiter(ResourceRequest asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
if (status == UniTaskStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -402,15 +402,15 @@ namespace UniRx.Async
|
|||
ResourceRequest asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public ResourceRequestConfiguredAwaiter(ResourceRequest asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: asyncOperation.isDone ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
@ -425,14 +425,14 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ namespace UniRx.Async
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -456,14 +456,14 @@ namespace UniRx.Async
|
|||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.asset;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
@ -552,12 +552,12 @@ namespace UniRx.Async
|
|||
GetResult(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus GetStatus(short token)
|
||||
public UniTaskStatus GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
public AwaiterStatus UnsafeGetStatus()
|
||||
public UniTaskStatus UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
@ -616,30 +616,30 @@ namespace UniRx.Async
|
|||
{
|
||||
AssetBundleRequest asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public AssetBundleRequestAwaiter(AssetBundleRequest asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.asset : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
if (status == UniTaskStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -683,15 +683,15 @@ namespace UniRx.Async
|
|||
AssetBundleRequest asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
UnityEngine.Object result;
|
||||
|
||||
public AssetBundleRequestConfiguredAwaiter(AssetBundleRequest asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: asyncOperation.isDone ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.asset;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
@ -706,14 +706,14 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public UnityEngine.Object GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -725,7 +725,7 @@ namespace UniRx.Async
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -737,14 +737,14 @@ namespace UniRx.Async
|
|||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.asset;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
@ -776,30 +776,30 @@ namespace UniRx.Async
|
|||
{
|
||||
AssetBundleCreateRequest asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
AssetBundle result;
|
||||
|
||||
public AssetBundleCreateRequestAwaiter(AssetBundleCreateRequest asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.assetBundle : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public AssetBundle GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
if (status == UniTaskStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -843,15 +843,15 @@ namespace UniRx.Async
|
|||
AssetBundleCreateRequest asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
AssetBundle result;
|
||||
|
||||
public AssetBundleCreateRequestConfiguredAwaiter(AssetBundleCreateRequest asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: asyncOperation.isDone ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.assetBundle;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
@ -866,14 +866,14 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public AssetBundle GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -885,7 +885,7 @@ namespace UniRx.Async
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -897,14 +897,14 @@ namespace UniRx.Async
|
|||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.assetBundle;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
@ -942,14 +942,14 @@ namespace UniRx.Async
|
|||
WWW asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
|
||||
public WWWConfiguredAwaiter(WWW asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: asyncOperation.isDone ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
||||
|
@ -962,15 +962,15 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded)
|
||||
if (status == UniTaskStatus.Succeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (status == AwaiterStatus.Canceled)
|
||||
else if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -982,7 +982,7 @@ namespace UniRx.Async
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -993,14 +993,14 @@ namespace UniRx.Async
|
|||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
@ -1039,30 +1039,30 @@ namespace UniRx.Async
|
|||
{
|
||||
UnityWebRequestAsyncOperation asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
UnityWebRequest result;
|
||||
|
||||
public UnityWebRequestAsyncOperationAwaiter(UnityWebRequestAsyncOperation asyncOperation)
|
||||
{
|
||||
this.status = asyncOperation.isDone ? AwaiterStatus.Succeeded : AwaiterStatus.Pending;
|
||||
this.status = asyncOperation.isDone ? UniTaskStatus.Succeeded : UniTaskStatus.Pending;
|
||||
this.asyncOperation = (this.status.IsCompleted()) ? null : asyncOperation;
|
||||
this.result = (this.status.IsCompletedSuccessfully()) ? asyncOperation.webRequest : null;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
|
||||
public UnityWebRequest GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Pending)
|
||||
if (status == UniTaskStatus.Pending)
|
||||
{
|
||||
// first timing of call
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
status = AwaiterStatus.Succeeded;
|
||||
status = UniTaskStatus.Succeeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1107,15 +1107,15 @@ namespace UniRx.Async
|
|||
UnityWebRequestAsyncOperation asyncOperation;
|
||||
IProgress<float> progress;
|
||||
CancellationToken cancellationToken;
|
||||
AwaiterStatus status;
|
||||
UniTaskStatus status;
|
||||
Action continuation;
|
||||
UnityWebRequest result;
|
||||
|
||||
public UnityWebRequestAsyncOperationConfiguredAwaiter(UnityWebRequestAsyncOperation asyncOperation, IProgress<float> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
this.status = cancellationToken.IsCancellationRequested ? AwaiterStatus.Canceled
|
||||
: asyncOperation.isDone ? AwaiterStatus.Succeeded
|
||||
: AwaiterStatus.Pending;
|
||||
this.status = cancellationToken.IsCancellationRequested ? UniTaskStatus.Canceled
|
||||
: asyncOperation.isDone ? UniTaskStatus.Succeeded
|
||||
: UniTaskStatus.Pending;
|
||||
|
||||
if (this.status.IsCompletedSuccessfully()) this.result = asyncOperation.webRequest;
|
||||
if (this.status.IsCompleted()) return;
|
||||
|
@ -1130,14 +1130,14 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
public bool IsCompleted => status.IsCompleted();
|
||||
public AwaiterStatus Status => status;
|
||||
public UniTaskStatus Status => status;
|
||||
void IAwaiter.GetResult() => GetResult();
|
||||
|
||||
public UnityWebRequest GetResult()
|
||||
{
|
||||
if (status == AwaiterStatus.Succeeded) return this.result;
|
||||
if (status == UniTaskStatus.Succeeded) return this.result;
|
||||
|
||||
if (status == AwaiterStatus.Canceled)
|
||||
if (status == UniTaskStatus.Canceled)
|
||||
{
|
||||
Error.ThrowOperationCanceledException();
|
||||
}
|
||||
|
@ -1149,7 +1149,7 @@ namespace UniRx.Async
|
|||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
InvokeContinuation(AwaiterStatus.Canceled);
|
||||
InvokeContinuation(UniTaskStatus.Canceled);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1161,14 +1161,14 @@ namespace UniRx.Async
|
|||
if (asyncOperation.isDone)
|
||||
{
|
||||
this.result = asyncOperation.webRequest;
|
||||
InvokeContinuation(AwaiterStatus.Succeeded);
|
||||
InvokeContinuation(UniTaskStatus.Succeeded);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InvokeContinuation(AwaiterStatus status)
|
||||
void InvokeContinuation(UniTaskStatus status)
|
||||
{
|
||||
this.status = status;
|
||||
var cont = this.continuation;
|
||||
|
|
|
@ -265,7 +265,7 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
bool IAwaiter.IsCompleted => isDisposed ? true : false;
|
||||
AwaiterStatus IAwaiter.Status => isDisposed ? AwaiterStatus.Canceled : AwaiterStatus.Pending;
|
||||
UniTaskStatus IAwaiter.Status => isDisposed ? UniTaskStatus.Canceled : UniTaskStatus.Pending;
|
||||
void IAwaiter.GetResult()
|
||||
{
|
||||
if (isDisposed) throw new OperationCanceledException();
|
||||
|
@ -381,7 +381,7 @@ namespace UniRx.Async
|
|||
}
|
||||
|
||||
bool IAwaiter.IsCompleted => isDisposed ? true : false;
|
||||
AwaiterStatus IAwaiter.Status => isDisposed ? AwaiterStatus.Canceled : AwaiterStatus.Pending;
|
||||
UniTaskStatus IAwaiter.Status => isDisposed ? UniTaskStatus.Canceled : UniTaskStatus.Pending;
|
||||
|
||||
T IAwaiter<T>.GetResult()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue