Skip to content

Promise was rejected with value Timeout of 00:00:10 reachedΒ #2175

@wellsjiang

Description

@wellsjiang

Version/platform/runtime used

Jint: 4.4.1
.net runtime: .net8

Describe the bug
The execution time of the asynchronous task must not exceed the default timeout of the Promise,
otherwise an error will occur: Promise was rejected with value Timeout of 00:00:10 reached

Code

static void Main(string[] args)
{
    try
    {
        using var engin = new Engine();
        engin.SetValue("log", (string value) => Console.WriteLine(value));
        engin.SetValue("setTimeout", (Action callback, int intvalMilliseconds) =>
        {
            Task.Delay(intvalMilliseconds).ContinueWith(_ =>
            {
                callback();
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
            return JsValue.Undefined;
        });
        var script = """
        async function testAsync(){
            const delayAsync = (interval)=>new Promise(resolve=>setTimeout(resolve, interval));
            log("begin delay");
            await delayAsync(11000);
            log("delay success")
        }
        """;
        engin.Execute(script);
        var value = engin.Evaluate("testAsync();");
        var resultValue = value.UnwrapIfPromise(TimeSpan.FromSeconds(30));
        Console.WriteLine("Success");
    }
    catch (Exception exception)
    {
        Console.WriteLine($"Evaluate Error: {exception}");
    }
    Console.ReadLine();
}

Expected behavior

begin delay
delay success

Actual behavior

begin delay
Evaluate Error: Jint.Runtime.PromiseRejectedException: Promise was rejected with value Timeout of 00:00:10 reached
   at Jint.Runtime.Throw.PromiseRejectedException(JsValue error)
   at Jint.JsValueExtensions.UnwrapIfPromise(JsValue value, TimeSpan timeout)
   at JintPromiseTimeout.Program.Main(String[] args) in JintPromiseTimeout\Program.cs:line 32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions