Calling async C# methods from JavaScript does not return a promise

I have an async function in my C# code:

public async Task<Boolean> DoSomethingAsync() { ... }
I want to call that from JS and await the result (as I talked with Marc, a Task<T> should be returned as a promise on JS side and the promise resolve callback should get the T as its value parameter).

So in JS I call it that way:

myCode.DoSomethingAsync().then(taskResult => {
    console.log("Task should return true: " + taskResult);

However the browser tells me that Uncaught TypeError: myCode.DoSomethingAsync(...).then is a not funtion.
So it seems the Task does not really gets translated/wrapped into a JS promise.
I attached a small repro project. Just the code in the MyCode.cs file and the call in the index.html, started by a separate button click. (29.2 KB)

I could have been mistaken here, last October we shipped

E25397: WebAssembly: await support for JS Promise

which was the issue i was recalling when we spoke, but reading it now, it looks like this is the reverse (using await on a promise). I’ll log an issue/feature request for this one.

Logged as bugs://E25881.

bugs://E25881 was closed as fixed.

This works now. Say you have (Mercury but the same really goes for C#):

  Public shared async Function Test() As Task(Of String)
    Return "hello"
  End Function
  Public Async Function Test2() As Task(Of String) 
    Return "Is it me you are looking for?"
  End function

You can do:

        result.Program_Test().then(function(b) {
            console.log("Tested " + b);
        var x = program.Test2()
        x.then(function(b) {
            console.log("Tested " + b);
        }); Tested hello Tested Is it me you are looking for?
1 Like