From 521bffd38b7d3e5546b1f7043d1bb3bd588e08c7 Mon Sep 17 00:00:00 2001 From: Nick Cuthbert Date: Wed, 17 Jan 2018 23:41:13 +0200 Subject: [PATCH] Fixed bug --- lib/actor.js | 4 ++-- lib/functions.js | 2 +- package.json | 4 ++-- test/actor.js | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/actor.js b/lib/actor.js index 463eddc..80810ce 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -21,7 +21,7 @@ class Actor { constructor (parent, name, system, f, { shutdownAfter, whenChildCrashes } = {}) { this.parent = parent; if (!name) { - name = `anonymous-${(Math.random() * Number.MAX_SAFE_INTEGER) | 0}`; + name = `anonymous-${Math.abs(Math.random() * Number.MAX_SAFE_INTEGER) | 0}`; } if (name && parent.children.has(name)) { throw new Error(`child actor of name ${name} already exists`); @@ -159,7 +159,7 @@ class Actor { } async handleFault (child, msg, sender, error) { - const ctx = child.createSupervisionContext(child, msg, sender, error); + const ctx = this.createSupervisionContext(child, msg, sender, error); const decision = await Promise.resolve(this.whenChildCrashes(msg, error, ctx)); switch (decision) { case SupervisionActions.stop: diff --git a/lib/functions.js b/lib/functions.js index fec9ef4..4410eb7 100644 --- a/lib/functions.js +++ b/lib/functions.js @@ -12,7 +12,7 @@ const query = (actor, msg, timeout, ...args) => { throw new Error('A timeout is required to be specified'); } - let concreteActor = systemMap.find(actor.system.name, actor); + const concreteActor = systemMap.find(actor.system.name, actor); return (concreteActor && concreteActor.query) ? concreteActor.query(msg, timeout, ...args) diff --git a/package.json b/package.json index 3e34063..731f9ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nact", - "version": "4.4.1", + "version": "4.4.2", "description": "nact ⇒ node.js + actors = your services have never been so µ", "main": "lib/index.js", "scripts": { @@ -51,4 +51,4 @@ "sinon": "^4.1.4", "sinon-chai": "^2.14.0" } -} +} \ No newline at end of file diff --git a/test/actor.js b/test/actor.js index 1b31c62..ee8425e 100644 --- a/test/actor.js +++ b/test/actor.js @@ -90,14 +90,14 @@ describe('Actor', function () { it('allows stateful behaviour', async function () { let actor = spawn( system, - function (state = '', msg) { - if (msg.type === 'query') { - dispatch(this.sender, state, this.self); - return state; - } else if (msg.type === 'append') { - return state + msg.payload; - } - } + function (state = '', msg) { + if (msg.type === 'query') { + dispatch(this.sender, state, this.self); + return state; + } else if (msg.type === 'append') { + return state + msg.payload; + } + } ); dispatch(actor, { payload: 'Hello ', type: 'append' }); @@ -212,7 +212,7 @@ describe('Actor', function () { it('should automatically stop after timeout if timeout is specified', async function () { console.error = ignore; - let child = spawnStateless(system, (msg) => {}, 'test', { shutdownAfter: 100 * milliseconds }); + let child = spawnStateless(system, (msg) => { }, 'test', { shutdownAfter: 100 * milliseconds }); await delay(110); isStopped(child).should.be.true; });