caoccao/Javet

How can I run asynchronously background task in V8?

Closed this issue · 4 comments

Does not it support?

like this

async function foo() {
    while (true) {
        // TODO SOME
        Thread.sleep(1000);
    }
}
foo();

// and can call another synchronous function
function test() {

}
// Java
// ... after call foo function

test.call(null, null);
// but above code is not work

I know that javenode comes out already, but is there no way?

Yes, you need to enable the V8 module. Project Javenode is a good example.

Then can't implement not only hand-made timer features but some background tasks? like expensive calculate (fibonacci) etc..

The pattern is the same. The async capability is powered by Promise. That project demonstrates how to implement Promise.

I will check that source! thank you for reply!