On Tue, Feb 11, 2020 at 8:42 PM Darin Dimitrov <darin.dimit...@gmail.com> wrote:
>
> I am embedding V8 in my C++ application and I have registered a custom "test" 
> function on the global object taking a callback as parameter:
>
> test(function() {
>     console.log("callback");
> });
>
> The "test" function starts a new thread and executes the callback on this 
> thread.
>
> Now I can wrap this function in a Promise:
>
> new Promise(function(resolve, reject) {
>     test(resolve);
> }).then(function() {
>     console.log("this callback is executed on the background thread created 
> by the 'test' function");
> });
>
> I am looking for a way to somehow hook into V8 promises so that they are 
> always resolved on the main thread of my application.
>
> I thought that using a custom platform might help but couldn't find any 
> useful method that I can override. It does provide the "CallOnWorkerThread" 
> method but can I relate this to promises? Does V8 provide some API to 
> intercept and replace the promise implementation?

Some additional info is needed because it's not wholly clear to me how
you envision this would work. How exactly is your program using
threads?

A V8 isolate is not reentrant. You can migrate it between threads but
only one thread can enter it (and should hold a v8::Locker to ensure
that it's the only one.)

You have some control over when microtasks (promises) are executed
with isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit) and
isolate->RunMicrotasks().

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CAHQurc8Qm2k699G%3DDXAdLA%2BC_vdfQFYJbU%3DnY8UM1JcF2xccMg%40mail.gmail.com.

Reply via email to