function sendMessage(com, fun = _ => _) {
				if (!('Passport' in com)) {
					log.w('Message has no Passport, ignored');
					log.w('    ' + JSON.stringify(com));
					fun('No Passport');
					return;
				}
				if (!('To' in com.Passport) || !com.Passport.To) {
					log.w('Message has no destination entity, ignored');
					log.w('    ' + JSON.stringify(com));
					fun('No recipient in message', com);
					return;
				}
				if (!('Pid' in com.Passport)) {
					log.w('Message has no message id, ignored');
					log.w('    ' + JSON.stringify(com));
					fun('No message id', com);
					return;
				}

				let pid = com.Passport.To;
				let apx = com.Passport.Apex || pid;
				if (pid in EntCache) {
					done(null, EntCache[pid]);
					return;
				} else {
					getEntityContext(pid, done);
				}

				async function done(err, entContextVolatile) {
					let entApex = await new Promise(res =>
						entContextVolatile.lock((val) => {
							res(val.Apex);
							return val;
						})
					);

					if (err) {
						log.w(err);
						log.w(JSON.stringify(com, null, 2));
						fun(err, com);
						return;
					}

					//TODO pid instanceOf ApexEntity
					if ((EntCache[pid].Apex == EntCache[pid].Pid) || (entApex == apx)) {
						let entContext = await new Promise(res => entContextVolatile.lock((context) => {
							res(context); return context;
						}));
						entContext.instance.dispatch(com, reply);
					} else {
						let err = 'Trying to send a message to a non-Apex'
							+ 'entity outside of the sending module';
						log.w(err);
						log.w(JSON.stringify(com, null, 2));
						fun(err, com);
					}
				}
				function reply(err, q) {
					// log.i('NEXUS MESSAGE:', com)
					fun(err, q);
				}
			}
function sendMessage(com, fun = _ => _) {
				if (!('Passport' in com)) {
					log.w('Message has no Passport, ignored');
					log.w('    ' + JSON.stringify(com));
					fun('No Passport');
					return;
				}
				if (!('To' in com.Passport) || !com.Passport.To) {
					log.w('Message has no destination entity, ignored');
					log.w('    ' + JSON.stringify(com));
					fun('No recipient in message', com);
					return;
				}
				if (!('Pid' in com.Passport)) {
					log.w('Message has no message id, ignored');
					log.w('    ' + JSON.stringify(com));
					fun('No message id', com);
					return;
				}

				let pid = com.Passport.To;
				let apx = com.Passport.Apex || pid;
				if (pid in EntCache) {
					done(null, EntCache[pid]);
					return;
				} else {
					getEntityContext(pid, done);
				}

				async function done(err, entContextVolatile) {
					let entApex = await new Promise(res =>
						entContextVolatile.lock((val) => {
							res(val.Apex);
							return val;
						})
					);

					if (err) {
						log.w(err);
						log.w(JSON.stringify(com, null, 2));
						fun(err, com);
						return;
					}

					//TODO pid instanceOf ApexEntity
					if ((EntCache[pid].Apex == EntCache[pid].Pid) || (entApex == apx)) {
						let entContext = await new Promise(res => entContextVolatile.lock((context) => {
							res(context); return context;
						}));
						entContext.instance.dispatch(com, reply);
					} else {
						let err = 'Trying to send a message to a non-Apex'
							+ 'entity outside of the sending module';
						log.w(err);
						log.w(JSON.stringify(com, null, 2));
						fun(err, com);
					}
				}
				function reply(err, q) {
					// log.i('NEXUS MESSAGE:', com)
					fun(err, q);
				}
			}
function sendMessage ( com , fun = _ => _ ) { if ( ! ( 'Passport' in com ) ) { log . w ( 'Message has no Passport, ignored' ) ; log . w ( '    ' + JSON . stringify ( com ) ) ; fun ( 'No Passport' ) ; return ; } if ( ! ( 'To' in com . Passport ) || ! com . Passport . To ) { log . w ( 'Message has no destination entity, ignored' ) ; log . w ( '    ' + JSON . stringify ( com ) ) ; fun ( 'No recipient in message' , com ) ; return ; } if ( ! ( 'Pid' in com . Passport ) ) { log . w ( 'Message has no message id, ignored' ) ; log . w ( '    ' + JSON . stringify ( com ) ) ; fun ( 'No message id' , com ) ; return ; } let pid = com . Passport . To ; let apx = com . Passport . Apex || pid ; if ( pid in EntCache ) { done ( null , EntCache [ pid ] ) ; return ; } else { getEntityContext ( pid , done ) ; } async function done ( err , entContextVolatile ) { let entApex = await new Promise ( res => entContextVolatile . lock ( ( val ) => { res ( val . Apex ) ; return val ; } ) ) ; if ( err ) { log . w ( err ) ; log . w ( JSON . stringify ( com , null , 2 ) ) ; fun ( err , com ) ; return ; } //TODO pid instanceOf ApexEntity if ( ( EntCache [ pid ] . Apex == EntCache [ pid ] . Pid ) || ( entApex == apx ) ) { let entContext = await new Promise ( res => entContextVolatile . lock ( ( context ) => { res ( context ) ; return context ; } ) ) ; entContext . instance . dispatch ( com , reply ) ; } else { let err = 'Trying to send a message to a non-Apex' + 'entity outside of the sending module' ; log . w ( err ) ; log . w ( JSON . stringify ( com , null , 2 ) ) ; fun ( err , com ) ; } } function reply ( err , q ) { // log.i('NEXUS MESSAGE:', com) fun ( err , q ) ; } }
Send a message from an entity to an Apex entity.
If a callback is provided, return when finished
@param {object} com 			the message object
@param {string} com.Cmd 		the command of the message
@param {object} com.Passport	the information about the message
@param {string} com.Passport.To the Pid of the recipient module
@param {string} com.Passport.Pid the ID of the message
@param {string=} com.Passport.From the Pid of the sending module
@callback fun 				the callback function to return to when finished
Send a message from an entity to an Apex entity . If a callback is provided return when finished