Skip to content

TaskPromiseConversion returns a Task with Status WaitingForActivation even when Promise is already resolved #641

@DavidBal

Description

@DavidBal

Hello,

i have the following code:

internal class Program
{
    static void Main(string[] args)
    {
        //Promise Task conversion
        using (V8ScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableTaskPromiseConversion))
        {
            engine.AddHostType("TestClass", typeof(TestClass));

            engine.Evaluate(
                """
                TestClass.executeScriptAction( async (x) => 
                {
                    return x.toLowerCase();
                }
                );
                """
                );

        }
    }
}

public static class TestClass
{
    public static void executeScriptAction(IJavaScriptObject obj)
    {
        //returns Task with Status -> TaskStatus.WaitingForActivation
        object result = obj.InvokeAsFunction("TestText");

        if (result is Task<object> resultAsTask)
        {
            //Waits forever here
            result = resultAsTask.GetAwaiter().GetResult();
        }

        Console.WriteLine(result);
    }
}

If i run this example the Promise from js is converted into a Task with the status WaitingForActivation and the code is waiting infinite for the Task to finish.
How could i receive the result of the js-function?

.csproj-File

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ClearScript" Version="7.4.5" />
  </ItemGroup>

</Project>

With kind regards,

David

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions