async function genModule(moduleDefinition, fun = _ => _) {
				moduleDefinition = JSON.parse(JSON.stringify(moduleDefinition));
				let moduleDefinitions = moduleDefinition;
				if ('Module' in moduleDefinition && (typeof moduleDefinition.Module == 'string')) {
					moduleDefinitions = { 'Top': moduleDefinition };
				}

				let Setup = {};
				let Start = {};
				let PromiseArray = [];
				let symbols = {};

				// loop over the keys to assign pids to the local dictionary and the
				// module definitions (moduleDefinitions)
				for (let key in moduleDefinitions) {
					symbols[key] = genPid();
				}

				//compile each module
				for (let moduleKey in moduleDefinitions) {
					//do a GetModule and compile instance for each 
					PromiseArray.push(new Promise((res, _rej) => {
						let inst = moduleDefinitions[moduleKey];
						GetModule(inst.Module, async function (err, mod) {
							if (err) {
								log.e('GenModule err -', err);
								fun(err);
								return;
							}
							let pidapx = symbols[moduleKey];

							for (let key in inst.Par) {
								let val = inst.Par[key];

								if (typeof val == 'string') {
									if (val.startsWith('$')) {
										let symbol = val.substr(1);
										if (symbol in symbols) {
											inst.Par[key] = symbols[symbol];
										} else {
											log.w(`${symbol} not in Module key list`);
											log.v(`${Object.keys(symbols)}`);
										}
									}

									if (val.startsWith('\\')) {
										let escaping = val.charAt(1);
										if (escaping == '$' || escaping == '\\') {
											//these are valid escape character
											inst.Par[key] = val.substr(1);
										} else {
											//invalid
											log.w(`\\${escaping} is not a valid escape sequence, ignoring.`);
										}
									}
								} else {
									inst.Par[key] = val;
								}
							}

							await compileInstance(pidapx, inst);

							let schema = await new Promise(async (res, _rej) => {
								if ('schema.json' in mod.files) {
									mod.file('schema.json').async('string').then(function (schemaString) {
										res(JSON.parse(schemaString));
									});
								} else {
									log.e('Module <' + inst.Module + '> schema not in ModCache');
									res();
									return;
								}
							});

							if ('$Setup' in schema.Apex)
								Setup[pidapx] = schema.Apex['$Setup'];
							if ('$Start' in schema.Apex)
								Start[pidapx] = schema.Apex['$Start'];
							res();
						});
					}));
				}

				await Promise.all(PromiseArray);

				log.v('Modules', JSON.stringify(symbols, null, 2));
				log.v('Setup', JSON.stringify(Setup, null, 2));
				log.v('Start', JSON.stringify(Start, null, 2));

				await setup();

				await start();

				fun(null, ('Top' in symbols) ? symbols['Top'] : null, symbols);


				/**
			 * Call setup on the required Module Apexes
			 */
				async function setup() {
					//build the setup promise array
					let setupArray = [];

					for (let pid in Setup) {
						setupArray.push(new Promise((resolve, _reject) => {
							let com = {};
							com.Cmd = Setup[pid];
							com.Passport = {};
							com.Passport.To = pid;
							com.Passport.Pid = genPid();
							sendMessage(com, resolve);
						}));
					}

					await Promise.all(setupArray);
				}

				/**
				 * Call Start on the required Module Apexes
				 */
				async function start() {
					//build the setup promise array
					let startArray = [];

					for (let pid in Start) {
						startArray.push(new Promise((resolve, _reject) => {
							let com = {};
							com.Cmd = Start[pid];
							com.Passport = {};
							com.Passport.To = pid;
							com.Passport.Pid = genPid();
							sendMessage(com, resolve);
						}));
					}

					await Promise.all(startArray);
				}
			}
async function genModule(moduleDefinition, fun = _ => _) {
				moduleDefinition = JSON.parse(JSON.stringify(moduleDefinition));
				let moduleDefinitions = moduleDefinition;
				if ('Module' in moduleDefinition && (typeof moduleDefinition.Module == 'string')) {
					moduleDefinitions = { 'Top': moduleDefinition };
				}

				let Setup = {};
				let Start = {};
				let PromiseArray = [];
				let symbols = {};

				
				
				for (let key in moduleDefinitions) {
					symbols[key] = genPid();
				}

				
				for (let moduleKey in moduleDefinitions) {
					
					PromiseArray.push(new Promise((res, _rej) => {
						let inst = moduleDefinitions[moduleKey];
						GetModule(inst.Module, async function (err, mod) {
							if (err) {
								log.e('GenModule err -', err);
								fun(err);
								return;
							}
							let pidapx = symbols[moduleKey];

							for (let key in inst.Par) {
								let val = inst.Par[key];

								if (typeof val == 'string') {
									if (val.startsWith('$')) {
										let symbol = val.substr(1);
										if (symbol in symbols) {
											inst.Par[key] = symbols[symbol];
										} else {
											log.w(`${symbol} not in Module key list`);
											log.v(`${Object.keys(symbols)}`);
										}
									}

									if (val.startsWith('\\')) {
										let escaping = val.charAt(1);
										if (escaping == '$' || escaping == '\\') {
											
											inst.Par[key] = val.substr(1);
										} else {
											
											log.w(`\\${escaping} is not a valid escape sequence, ignoring.`);
										}
									}
								} else {
									inst.Par[key] = val;
								}
							}

							await compileInstance(pidapx, inst);

							let schema = await new Promise(async (res, _rej) => {
								if ('schema.json' in mod.files) {
									mod.file('schema.json').async('string').then(function (schemaString) {
										res(JSON.parse(schemaString));
									});
								} else {
									log.e('Module <' + inst.Module + '> schema not in ModCache');
									res();
									return;
								}
							});

							if ('$Setup' in schema.Apex)
								Setup[pidapx] = schema.Apex['$Setup'];
							if ('$Start' in schema.Apex)
								Start[pidapx] = schema.Apex['$Start'];
							res();
						});
					}));
				}

				await Promise.all(PromiseArray);

				log.v('Modules', JSON.stringify(symbols, null, 2));
				log.v('Setup', JSON.stringify(Setup, null, 2));
				log.v('Start', JSON.stringify(Start, null, 2));

				await setup();

				await start();

				fun(null, ('Top' in symbols) ? symbols['Top'] : null, symbols);


				
				async function setup() {
					
					let setupArray = [];

					for (let pid in Setup) {
						setupArray.push(new Promise((resolve, _reject) => {
							let com = {};
							com.Cmd = Setup[pid];
							com.Passport = {};
							com.Passport.To = pid;
							com.Passport.Pid = genPid();
							sendMessage(com, resolve);
						}));
					}

					await Promise.all(setupArray);
				}

				
				async function start() {
					
					let startArray = [];

					for (let pid in Start) {
						startArray.push(new Promise((resolve, _reject) => {
							let com = {};
							com.Cmd = Start[pid];
							com.Passport = {};
							com.Passport.To = pid;
							com.Passport.Pid = genPid();
							sendMessage(com, resolve);
						}));
					}

					await Promise.all(startArray);
				}
			}
async function genModule ( moduleDefinition , fun = _ => _ ) { moduleDefinition = JSON . parse ( JSON . stringify ( moduleDefinition ) ) ; let moduleDefinitions = moduleDefinition ; if ( 'Module' in moduleDefinition && ( typeof moduleDefinition . Module == 'string' ) ) { moduleDefinitions = { 'Top' : moduleDefinition } ; } let Setup = { } ; let Start = { } ; let PromiseArray = [ ] ; let symbols = { } ; // loop over the keys to assign pids to the local dictionary and the // module definitions (moduleDefinitions) for ( let key in moduleDefinitions ) { symbols [ key ] = genPid ( ) ; } //compile each module for ( let moduleKey in moduleDefinitions ) { //do a GetModule and compile instance for each  PromiseArray . push ( new Promise ( ( res , _rej ) => { let inst = moduleDefinitions [ moduleKey ] ; GetModule ( inst . Module , async function ( err , mod ) { if ( err ) { log . e ( 'GenModule err -' , err ) ; fun ( err ) ; return ; } let pidapx = symbols [ moduleKey ] ; for ( let key in inst . Par ) { let val = inst . Par [ key ] ; if ( typeof val == 'string' ) { if ( val . startsWith ( '$' ) ) { let symbol = val . substr ( 1 ) ; if ( symbol in symbols ) { inst . Par [ key ] = symbols [ symbol ] ; } else { log . w ( ` ${ symbol } ` ) ; log . v ( ` ${ Object . keys ( symbols ) } ` ) ; } } if ( val . startsWith ( '\\' ) ) { let escaping = val . charAt ( 1 ) ; if ( escaping == '$' || escaping == '\\' ) { //these are valid escape character inst . Par [ key ] = val . substr ( 1 ) ; } else { //invalid log . w ( ` \\ ${ escaping } ` ) ; } } } else { inst . Par [ key ] = val ; } } await compileInstance ( pidapx , inst ) ; let schema = await new Promise ( async ( res , _rej ) => { if ( 'schema.json' in mod . files ) { mod . file ( 'schema.json' ) . async ( 'string' ) . then ( function ( schemaString ) { res ( JSON . parse ( schemaString ) ) ; } ) ; } else { log . e ( 'Module <' + inst . Module + '> schema not in ModCache' ) ; res ( ) ; return ; } } ) ; if ( '$Setup' in schema . Apex ) Setup [ pidapx ] = schema . Apex [ '$Setup' ] ; if ( '$Start' in schema . Apex ) Start [ pidapx ] = schema . Apex [ '$Start' ] ; res ( ) ; } ) ; } ) ) ; } await Promise . all ( PromiseArray ) ; log . v ( 'Modules' , JSON . stringify ( symbols , null , 2 ) ) ; log . v ( 'Setup' , JSON . stringify ( Setup , null , 2 ) ) ; log . v ( 'Start' , JSON . stringify ( Start , null , 2 ) ) ; await setup ( ) ; await start ( ) ; fun ( null , ( 'Top' in symbols ) ? symbols [ 'Top' ] : null , symbols ) ; /**
			 * Call setup on the required Module Apexes
			 */ async function setup ( ) { //build the setup promise array let setupArray = [ ] ; for ( let pid in Setup ) { setupArray . push ( new Promise ( ( resolve , _reject ) => { let com = { } ; com . Cmd = Setup [ pid ] ; com . Passport = { } ; com . Passport . To = pid ; com . Passport . Pid = genPid ( ) ; sendMessage ( com , resolve ) ; } ) ) ; } await Promise . all ( setupArray ) ; } /**
				 * Call Start on the required Module Apexes
				 */ async function start ( ) { //build the setup promise array let startArray = [ ] ; for ( let pid in Start ) { startArray . push ( new Promise ( ( resolve , _reject ) => { let com = { } ; com . Cmd = Start [ pid ] ; com . Passport = { } ; com . Passport . To = pid ; com . Passport . Pid = genPid ( ) ; sendMessage ( com , resolve ) ; } ) ) ; } await Promise . all ( startArray ) ; } }
Starts an instance of a module that exists in the cache.
After generating, the instance Apex receives a setup and start command synchronously
@param {Object} inst 		Definition of the instance to be
spun up or an object of multiple definitions
@param {string?} inst.Module 	The name of the module to spin up
@param {Object=} inst.Par	The par of the to be encorporated with the Module Apex Par
@callback fun 				(err, pid of module apex)
Starts an instance of a module that exists in the cache . After generating the instance Apex receives a setup and start command synchronously