lib/incoming-handlers.js
function referenceProtection(session) {
  function checkScope(funcName) {
    return (msg) => {
      if (typeof session[funcName] === 'function') {
        session[funcName](msg);
      }
    }
  }
  return {
    actor: session.actor,
    debug: checkScope('debug'),
    sendToClient: checkScope('sendToClient')
  }
}
function referenceProtection(session) {
  function checkScope(funcName) {
    return (msg) => {
      if (typeof session[funcName] === 'function') {
        session[funcName](msg);
      }
    }
  }
  return {
    actor: session.actor,
    debug: checkScope('debug'),
    sendToClient: checkScope('sendToClient')
  }
}
function referenceProtection ( session ) { function checkScope ( funcName ) { return ( msg ) => { if ( typeof session [ funcName ] === 'function' ) { session [ funcName ] ( msg ) ; } } } return { actor : session . actor , debug : checkScope ( 'debug' ) , sendToClient : checkScope ( 'sendToClient' ) } }
if the platform throws an exception, the worker will kill & restart it, however if a callback comes in there could be a race condition which tries to still access session functions which have already been terminated by the worker. this function wrapper only calls the session functions if they still exist.
if the platform throws an exception the worker will kill & restart it however if a callback comes in there could be a race condition which tries to still access session functions which have already been terminated by the worker . this function wrapper only calls the session functions if they still exist .