Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks cannot be executed sequentially #1817

Open
wellsjiang opened this issue Mar 26, 2024 · 0 comments
Open

Tasks cannot be executed sequentially #1817

wellsjiang opened this issue Mar 26, 2024 · 0 comments

Comments

@wellsjiang
Copy link

Version used

3.0.1

Describe the bug

Tasks cannot be executed sequentially

Code

var engine = new Engine(option =>
{
    option.DebugMode(false);
    option.TimeZone = TimeZoneInfo.Utc;
});
engine.Execute("const global = this;");
engine.Execute("const exports = {};");
engine.SetValue("console", new ConsoleService());
engine.SetValue("InternalSetTimeout", async (int delay) =>
{
    await Task.Delay(delay);
});
engine.Evaluate(@"
function setTimeout(callback, interval){
    InternalSetTimeout(interval).then(success=> {
        callback();
    }).catch(error=>{
        console.log(error)
    })
}");
Console.WriteLine($"Begin: {DateTime.UtcNow}");
var script = @"
setTimeout(()=>console.log('5000', new Date()), 5000);
setTimeout(()=>console.log('3000', new Date()), 3000);
setTimeout(()=>console.log('1000', new Date()), 1000);";
engine.Evaluate(script).UnwrapIfPromise();

Expected behavior

Begin: 2024/3/26 3:08:27
1000 2024/3/26 3:08:28
3000 2024/3/26 3:08:30
5000 2024/3/26 3:08:32

Actual behavior

Begin: 2024/3/26 3:08:27
1000 2024/3/26 3:08:32
3000 2024/3/26 3:08:32
5000 2024/3/26 3:08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant