Func<UniTask<T>> delegate parameter
flowerhouse-dev opened this issue · comments
Jesse commented
I'm trying to pass a UniTask<T>
method as a parameter using Func
.
public static async UniTask<T> Async<T>(Func<UniTask<T>> function)
{
T returnValue = await function.Invoke();
return returnValue;
}
But when I call it as follows, it says the argument type does not match.
Argument type 'Cysharp.Threading.Tasks.UniTask<MyType>' is not assignable to parameter type 'System.Func<Cysharp.Threading.Tasks.UniTask<MyType>>'
MyType result = await MyClass.Async<MyType>(UniTaskMethod(myParameter));
private async UniTask<MyType> UniTaskMethod(ParameterType myParameter)
{
// async stuff
}
I can't figure out how I can get this to work.
Tim Cassell commented
You're calling UniTaskMethod
, not passing a delegate to it. Try this.
MyType result = await MyClass.Async<MyType>(() => UniTaskMethod(myParameter));
Jesse commented
Duh.. thanks!