help icon indicating copy to clipboard operation
help copied to clipboard

Embedding: Create more than one Environment

Open alvarolb opened this issue 3 years ago • 2 comments

Details

Hi, the default embedding example illustrates how to create and run a single Environment... but, is it possible to create more than one Environment by using the CommonEnvironmentSetup::Create function?

I am getting the following runtime error:

Assertion `(start_io_thread_async_initialized.exchange(true)) == (false)' failed.

Any ideas?

Node.js version

Node v17.4.0

Example code

No response

Operating system

Linux

Scope

runtime

Module and version

Not applicable.

alvarolb avatar Feb 04 '22 20:02 alvarolb

is it possible to create more than one Environment by using the CommonEnvironmentSetup::Create function

No.

In this case, you will need to create the uv event loop, ArrayBufferAllocator, Isolate, Context and Environment manually. For example, it’s not clear whether you want the different Environment instances to share an event loop or Isolate or have distinct ones.

You are seeing the crash above because only one environment can have kOwnsInspector set at a time.

You can also take a look at https://github.com/addaleax/synchronous-worker for examples, it is a native addon that creates new Environment instances which optionally share an event loop (but always share a thread + Isolate).

addaleax avatar Feb 07 '22 16:02 addaleax

@alvarolb - is this resolved?

gireeshpunathil avatar Jun 21 '22 03:06 gireeshpunathil

closing as solution provided

gireeshpunathil avatar Aug 02 '23 02:08 gireeshpunathil