pjs.registerAsyncName()
Description
Globally registers an async function name to trigger automatic addition of the await keyword when the function is used. This API can be used during server startup to load and register globally shared function names.
Parameters
Function name (String) - The name of the async function to register.
Examples
Register a Globally Shared Async Function
start.js
// start.js -- register the shared helper once, while the server is starting.
if (!global.mycompany) global.mycompany = {};
if (!mycompany.utils) mycompany.utils = {};
mycompany.utils.usefulFunction = pjs.require("utils/usefulFunction.js");
// Tell Profound.js that this name is asynchronous. From this point on, every
// module that calls it has "await" inserted automatically during transformation.
pjs.registerAsyncName("mycompany.utils.usefulFunction");Calling the Registered Function From a Module
Any Profound.js module
// Any Profound.js module can now call the shared helper top-down: no "await"
// in the source, and no per-module pjs.require().
function main() {
pjs.define("customerName", { type: "char", length: 50 });
// Because the name was registered in start.js, this resolves to the returned
// value. Without pjs.registerAsyncName(), the pending Promise would be
// assigned instead, and customerName would not hold the customer's name.
customerName = mycompany.utils.usefulFunction(4711);
console.log(customerName);
}
module.exports.run = main;