Closed YImhof closed 10 months ago
Hi @YImhof,
The issue seems to be from the implementation of fromPromises:
promise.then(function () {
tcs.setResult(handler ? handler.apply(null, arguments) : Array.prototype.slice.call(arguments, 0));
}, function () {
tcs.setException(errorHandler ? errorHandler.apply(null, arguments) : new H5.PromiseException(Array.prototype.slice.call(arguments, 0)));
}, progressHandler);
As you can see, arguments is the calling arguments from the function on promise.then, and it is just passed as the result to the Task.
That's why the signature of Task.FromPromise is
public static extern Task<object[]> FromPromise(IPromise promise);
I think the right way for you to use the template should be instead to pass the argument number you want from the response in the "handler" argument:
[External]
[Name("idProvider")]
internal static class IdProvider
{
[Template("System.Threading.Tasks.Task.fromPromise({this}.isLoginRedirect(), 0)")] // <<<<< Add 0 here
public static extern Task<bool> IsLoginRedirect();
}
Hello @theolivenbaum,
Thanks a lot for the feed-back and the solution. I tried it and the problem is solved.
Sorry that I missed the point of the input arguments pass-through.
No worries, I was also not aware of it 😅
In case of conversion from
Promise
toTask
returning a result, thegetAwaitedResult
method returns the result encapsulated in an array.For example, the following code never logs the resulting
Response
object, asresponse.status
isundefined
.Part of the transpiled code to JS:
Variable
$tr1
is an array of length 1 having theResponse
object at index 0. So perhaps, the lineresponse = $tr1;
should beresponse = $tr1[0];
?For a complete information, you have to know that i am trying to create a h5 proxy for an existing TS class that returns promises, doing something similar to the above code, like the following:
Calling
IsLoginRedirect
makes a call to the server getting an OIdC configuration to be applied, and so is asynchrone. In both cases,getAwaitedResult
returns the unexpected array object.