Add UniTask.Run(Func<UniTask>) overload
parent
0640f278cc
commit
81f9c55c7f
|
@ -50,6 +50,50 @@ namespace Cysharp.Threading.Tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
|
public static async UniTask Run(Func<UniTask> action, bool configureAwait = true)
|
||||||
|
{
|
||||||
|
await UniTask.SwitchToThreadPool();
|
||||||
|
|
||||||
|
if (configureAwait)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await action();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
|
public static async UniTask Run(Func<object, UniTask> action, object state, bool configureAwait = true)
|
||||||
|
{
|
||||||
|
await UniTask.SwitchToThreadPool();
|
||||||
|
|
||||||
|
if (configureAwait)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await action(state);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await action(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
public static async UniTask<T> Run<T>(Func<T> func, bool configureAwait = true)
|
public static async UniTask<T> Run<T>(Func<T> func, bool configureAwait = true)
|
||||||
{
|
{
|
||||||
|
@ -71,6 +115,27 @@ namespace Cysharp.Threading.Tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
|
public static async UniTask<T> Run<T>(Func<UniTask<T>> func, bool configureAwait = true)
|
||||||
|
{
|
||||||
|
await UniTask.SwitchToThreadPool();
|
||||||
|
if (configureAwait)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await func();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return await func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
public static async UniTask<T> Run<T>(Func<object, T> func, object state, bool configureAwait = true)
|
public static async UniTask<T> Run<T>(Func<object, T> func, object state, bool configureAwait = true)
|
||||||
{
|
{
|
||||||
|
@ -92,6 +157,28 @@ namespace Cysharp.Threading.Tasks
|
||||||
return func(state);
|
return func(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
|
public static async UniTask<T> Run<T>(Func<object, UniTask<T>> func, object state, bool configureAwait = true)
|
||||||
|
{
|
||||||
|
await UniTask.SwitchToThreadPool();
|
||||||
|
|
||||||
|
if (configureAwait)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await func(state);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return await func(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue