mirror of https://github.com/Cysharp/UniTask
Detach continuations of AsyncOperationHandle from the Completed callback
parent
e999268305
commit
213915b06d
|
@ -44,7 +44,21 @@ namespace Cysharp.Threading.Tasks
|
||||||
return UniTask.CompletedTask;
|
return UniTask.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, out var token), token);
|
var task = new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, out var token), token);
|
||||||
|
return DetachContinuationFromAsyncOperationHandleCompletedCallback(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async UniTask DetachContinuationFromAsyncOperationHandleCompletedCallback(UniTask task)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await task;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Completed callback is deferred until the LateUpdate of the current frame,
|
||||||
|
await UniTask.Yield(PlayerLoopTiming.PostLateUpdate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion
|
public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion
|
||||||
|
@ -255,7 +269,21 @@ namespace Cysharp.Threading.Tasks
|
||||||
return UniTask.FromResult(handle.Result);
|
return UniTask.FromResult(handle.Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellationToken, out var token), token);
|
var task = new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellationToken, out var token), token);
|
||||||
|
return DetachContinuationFromAsyncOperationHandleCompletedCallback(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async UniTask<T> DetachContinuationFromAsyncOperationHandleCompletedCallback<T>(UniTask<T> task)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await task;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Completed callback is deferred until the LateUpdate of the current frame,
|
||||||
|
await UniTask.Yield(PlayerLoopTiming.PostLateUpdate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class AsyncOperationHandleConfiguredSource<T> : IUniTaskSource<T>, IPlayerLoopItem, ITaskPoolNode<AsyncOperationHandleConfiguredSource<T>>
|
sealed class AsyncOperationHandleConfiguredSource<T> : IUniTaskSource<T>, IPlayerLoopItem, ITaskPoolNode<AsyncOperationHandleConfiguredSource<T>>
|
||||||
|
|
Loading…
Reference in New Issue