Closed User124125 closed 4 years ago
@AlexPGithub what version of Unity are you using? and what version of .NET Framework?
There's no reason the promises shouldn't work inside Tasks although if your task is running on another thread I'm not sure how well Unity handles sending messages to the Debug.Log from different threads. Are you able to attach a debugger to the code? My first guess here would be that RestClient.Post
is never resolving, which is possible if there is no timeout for the web request.
While technically it is possible to use promises with async/await code, you should never do this. Choose one approach an go with it all the way.
As for your sample, RestClient is based on UnityWebRequest (afaik). If so, it might not work as expected when used in any non-Unity thread (like most Unity APIs). Another problem with it, it assumes the Then is called on the same thread as Post, which is probably not the case.
Here's how your method should look like:
private Task AuthenticateAsync()
{
var tcs = new TaskCompletionSource<object>();
RestClient.Post<signInResponse_model>(someUri, someString)
.Then(res =>
{
currentIDToken = res.idToken;
currentUID = res.idToken;
tcs.SetResult(null);
})
.Catch(error =>
{
Debug.LogException(error);
tcs.SetException(error);
});
return tcs.Task;
}
Hi there, im quite a noob so please correct me.
Is it possible that the promises are not usable inside a task?
I have this function and it wont work inside the task.Run(), but it works outside of task.Run()
It does not Debug.Log anything at all ...