diff --git a/lib/actor.js b/lib/actor.js index 71b5750..57a21e7 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -20,7 +20,7 @@ class Actor { this.path = parent.path.createChildPath(this.name); this.system = system; this.reference = new ActorReference(this.system.name, this.parent.reference, this.path, this.name); - this.log = this.system.createLogger || this.system.createLogger(this.reference); + this.log = this.system.createLogger(this.reference); this.f = f; this.state = undefined; this.stopped = false; @@ -202,13 +202,7 @@ const spawn = (parent, f, name, properties) => systemMap.applyOrThrowIfStopped(parent, p => p.assertNotStopped() && new Actor(p, name, p.system, f, properties).reference); const spawnStateless = (parent, f, name, properties) => - spawn(parent, function (state, msg, ctx) { - try { - return f.call(ctx, msg, ctx); - } catch (e) { - console.error(e); - } - }, name, properties); + spawn(parent, (state, msg, ctx) => f.call(ctx, msg, ctx), name, { onCrash: (_, __, ctx) => ctx.resume, ...properties }); module.exports.spawn = spawn; module.exports.spawnStateless = spawnStateless; diff --git a/lib/monitoring/index.js b/lib/monitoring/index.js index e8eb1ac..5f994e6 100644 --- a/lib/monitoring/index.js +++ b/lib/monitoring/index.js @@ -12,7 +12,7 @@ const { logToConsole } = require('./console-engine'); const configureLogging = (engine) => (system) => { const loggingActor = engine(system.reference); if (loggingActor) { - return Object.assign(system, { createLogger: (reference) => new LoggingFacade(loggingActor, reference) }); + system.createLogger = (reference) => new LoggingFacade(loggingActor, reference); } else { throw new Error('Logging engine is not defined'); } diff --git a/lib/system.js b/lib/system.js index 30a0d76..547d04f 100644 --- a/lib/system.js +++ b/lib/system.js @@ -15,6 +15,7 @@ class ActorSystem { constructor (extensions) { let [hd, ...tail] = extensions; this.children = new Map(); + this.createLogger = () => undefined; this.name = (typeof (hd) === 'object' && hd.name) || generateSystemId(); this.path = ActorPath.root(this.name); this.reference = new ActorSystemReference(this.name, this.path); diff --git a/test/actor.js b/test/actor.js index 24525a6..75f5a71 100644 --- a/test/actor.js +++ b/test/actor.js @@ -32,7 +32,7 @@ const children = (reference) => { } }; -const ignore = () => { }; +const ignore = () => {}; const retry = async (assertion, remainingAttempts, retryInterval = 0) => { if (remainingAttempts <= 1) { @@ -55,6 +55,7 @@ describe('ActorReference', function () { it('should have name, path, parent, properties', function () { let child = spawnStateless(system, ignore); let grandchild = spawnStateless(child, ignore); + console.error(child.parent); child.parent.should.equal(system); grandchild.parent.should.equal(child); child.name.should.be.a('string');