Replies: 2 comments 2 replies
-
Hi @nextfool,
ClearScript doesn't expose script engine internals.
The .NET platform includes asynchronous I/O and synchronization facilities as part of its standard API set. Our worker sample demonstrates how asynchronous event loops and cross-runtime communications can be implemented without engine internals or additional libraries. Please let us know what it's missing.
Please clarify. What would you like to do, specifically, that the existing API doesn't allow you to do? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi @nextfool,
You don't have to. V8 processes the microtask queue automatically when it exits from the outermost script scope.
You can use promises to implement such a function: dynamic addQueueMicrotask = engine.Evaluate(@"(function (onError) {
queueMicrotask = (function (fn) {
Promise.resolve().then(fn).catch(onError);
return undefined;
}).bind();
})");
addQueueMicrotask(new Action<object>(error => {
var message = error is ScriptObject obj ? obj.InvokeMethod("toString") : error.ToString();
Console.WriteLine("Uncaught " + message);
})); Please let us know if we're missing something. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi @ClearScriptLib ,
Since V8 does not support any web api(setTimeout, postMessage etc.), I have to implement them myself. So I have created my own "event loop". But V8 DOES support promises, and thus it has its own "microtask queue", and it is out of my control.
Now my questions are:
1.How do I access v8's "microtask queue" and integrate it into my "event loop"? I guess it is not possible isn't?
2. Does Clearscript have any infrastructure to allow me to extend v8's internal queue?
3. Do you have plan to include "libuv"(used by Nodejs) or any other similar component into Clearscript, so that it has the "official" event loop?
So basically what I need is a way to "sync" between the promises and my "event loop", so that the script runs in my engine would feel like it's running in Nodejs or a browser.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions