-
-
Notifications
You must be signed in to change notification settings - Fork 586
Open
Description
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
esmoley
Metadata
Metadata
Assignees
Labels
No labels