Embedding: Create more than one Environment
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.
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).
@alvarolb - is this resolved?
closing as solution provided