nl_tokens: Send a message from an entity to an Apex entity . If a callback is provided return when finished
pl_tokens: 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' <mask> 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 ) ; } }