mirror of https://github.com/Cysharp/UniTask
Merge pull request #538 from kochounoyume/argument-allowed-factory
Factory method allowed argumentpull/565/head
commit
0c8057c668
|
@ -81,6 +81,16 @@ namespace Cysharp.Threading.Tasks
|
|||
return factory();
|
||||
}
|
||||
|
||||
public static UniTask Create(Func<CancellationToken, UniTask> factory, CancellationToken cancellationToken)
|
||||
{
|
||||
return factory(cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask Create<T>(T state, Func<T, UniTask> factory)
|
||||
{
|
||||
return factory(state);
|
||||
}
|
||||
|
||||
public static UniTask<T> Create<T>(Func<UniTask<T>> factory)
|
||||
{
|
||||
return factory();
|
||||
|
@ -137,11 +147,19 @@ namespace Cysharp.Threading.Tasks
|
|||
return () => asyncAction(cancellationToken).Forget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// helper of create add UniTaskVoid to delegate.
|
||||
/// </summary>
|
||||
public static Action Action<T>(T state, Func<T, UniTaskVoid> asyncAction)
|
||||
{
|
||||
return () => asyncAction(state).Forget();
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
|
||||
/// <summary>
|
||||
/// Create async void(UniTaskVoid) UnityAction.
|
||||
/// For exampe: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } ))
|
||||
/// For example: onClick.AddListener(UniTask.UnityAction(async () => { /* */ } ))
|
||||
/// </summary>
|
||||
public static UnityEngine.Events.UnityAction UnityAction(Func<UniTaskVoid> asyncAction)
|
||||
{
|
||||
|
@ -150,13 +168,22 @@ namespace Cysharp.Threading.Tasks
|
|||
|
||||
/// <summary>
|
||||
/// Create async void(UniTaskVoid) UnityAction.
|
||||
/// For exampe: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy()))
|
||||
/// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy()))
|
||||
/// </summary>
|
||||
public static UnityEngine.Events.UnityAction UnityAction(Func<CancellationToken, UniTaskVoid> asyncAction, CancellationToken cancellationToken)
|
||||
{
|
||||
return () => asyncAction(cancellationToken).Forget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create async void(UniTaskVoid) UnityAction.
|
||||
/// For example: onClick.AddListener(UniTask.UnityAction(FooAsync, Argument))
|
||||
/// </summary>
|
||||
public static UnityEngine.Events.UnityAction UnityAction<T>(T state, Func<T, UniTaskVoid> asyncAction)
|
||||
{
|
||||
return () => asyncAction(state).Forget();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue