Search code examples
javascriptnode.jsmultithreadingasynchronousv8

NodeJS: Get Current VM Context


Node JS executes the codebase in the Javascript VX (V8 currently) engine, and executes every asynchronous context in its own VM.

Given this information, is there an API that allows to find in which VM context the current code execution is taking place?

I am attempting to create context-specific globals.

Is this possible? Is my understanding of Node correct?


Solution

  • Your understanding of node is incorrect. Specifically you said:

    Javascript VX (V8 currently) engine, and executes every asynchronous context in its own VM

    No. Javascript has only one context. The current VM. There are multithreading extensions in node.js such as webworker-threads but they're not often used because:

    1. They rarely improve throughput and almost always increase latency
    2. They're almost never necessary because almost nothing in node.js blocks

    If you want a slightly more low-level technical detail of how asynchronous execution work in node.js see my answer to this question: I know that callback function runs asynchronously, but why?