Add UniTask.Yield(CancellationToken), NextFrame(CancellationToken)

master
neuecc 2021-03-01 19:08:40 +09:00
parent e57a4332ec
commit cdda33a98e
1 changed files with 38 additions and 2 deletions

View File

@ -20,12 +20,23 @@ namespace Cysharp.Threading.Tasks
public partial struct UniTask public partial struct UniTask
{ {
public static YieldAwaitable Yield(PlayerLoopTiming timing = PlayerLoopTiming.Update) public static YieldAwaitable Yield()
{
// optimized for single continuation
return new YieldAwaitable(PlayerLoopTiming.Update);
}
public static YieldAwaitable Yield(PlayerLoopTiming timing)
{ {
// optimized for single continuation // optimized for single continuation
return new YieldAwaitable(timing); return new YieldAwaitable(timing);
} }
public static UniTask Yield(CancellationToken cancellationToken)
{
return new UniTask(YieldPromise.Create(PlayerLoopTiming.Update, cancellationToken, out var token), token);
}
public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken) public static UniTask Yield(PlayerLoopTiming timing, CancellationToken cancellationToken)
{ {
return new UniTask(YieldPromise.Create(timing, cancellationToken, out var token), token); return new UniTask(YieldPromise.Create(timing, cancellationToken, out var token), token);
@ -34,11 +45,36 @@ namespace Cysharp.Threading.Tasks
/// <summary> /// <summary>
/// Similar as UniTask.Yield but guaranteed run on next frame. /// Similar as UniTask.Yield but guaranteed run on next frame.
/// </summary> /// </summary>
public static UniTask NextFrame(PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default) public static UniTask NextFrame()
{
return new UniTask(NextFramePromise.Create(PlayerLoopTiming.Update, CancellationToken.None, out var token), token);
}
/// <summary>
/// Similar as UniTask.Yield but guaranteed run on next frame.
/// </summary>
public static UniTask NextFrame(PlayerLoopTiming timing)
{
return new UniTask(NextFramePromise.Create(timing, CancellationToken.None, out var token), token);
}
/// <summary>
/// Similar as UniTask.Yield but guaranteed run on next frame.
/// </summary>
public static UniTask NextFrame(CancellationToken cancellationToken)
{
return new UniTask(NextFramePromise.Create(PlayerLoopTiming.Update, cancellationToken, out var token), token);
}
/// <summary>
/// Similar as UniTask.Yield but guaranteed run on next frame.
/// </summary>
public static UniTask NextFrame(PlayerLoopTiming timing, CancellationToken cancellationToken)
{ {
return new UniTask(NextFramePromise.Create(timing, cancellationToken, out var token), token); return new UniTask(NextFramePromise.Create(timing, cancellationToken, out var token), token);
} }
/// <summary> /// <summary>
/// Same as UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate). /// Same as UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate).
/// </summary> /// </summary>