Skip to content

Top level await for Node.js process #59

@ccmcintyre-kingsds

Description

@ccmcintyre-kingsds

Node.js supports await/async behaviour even in the top-level scope, either through the --harmony-top-level-await flag prior to Node.js 14.8, or for ES modules since Node.js 14.9. Qualifying as an ES module for the purpose of this feature is in principle achievable using .mjs file extensions, declaring "type": "module" in the relevant package.json file, or by passing an --input-type=module flag to the node process when eval-ing script strings. This lattermost option sounds most relevant to Bifrost, but evidence suggests that none of these flags are meaningful when passed to to the Node.js process initialization (via subprocess.Popen in python, at py_nodejs.py), which is setting up a process which will be called via streaming pipes and populated via shared memory, rather than passing scripts to be directly eval-ed by a new Node.js process.

Top-level await is a desirable feature to support for Bifrost broadly, if possible. When investigating solutions, please consider both the above caveats relating to the relevant flags, and also consider how solutions might impact or be impacted by the following behaviour of Bifrost's current script evaluation code, taken from main.js:

//evaluate some script in the given context.
//Note that we await in order to allow for scripts which end in a promise
//to fully complete
async evaluate(script){
    await vm.runInContext(script, this.context);
}

Whatever solution is implemented should be able to support the async initalization of dcp-client using top-level await.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjavascriptRelates to JavaScript or Node.js codepipesRelates to interprocess streamingpythonRelates to Python code

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions