Skip to content

Commit

Permalink
Updated stateless actor
Browse files Browse the repository at this point in the history
  • Loading branch information
ncthbrt committed Apr 16, 2018
1 parent 05f5166 commit 74f5a20
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ const spawn = (parent, f, name, properties) =>
const spawnStateless = (parent, f, name, properties) =>
spawn(parent, function (state, msg, ctx) {
try {
f.call(ctx, msg, ctx);
return Promise.resolve(f.call(ctx, msg, ctx)).then((_) => true);
} catch (e) {
console.error(e);
return true;
}
return true;
}, name, properties);

module.exports.spawn = spawn;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nact",
"version": "6.0.4",
"version": "6.1.0",
"description": "nact ⇒ node.js + actors = your services have never been so µ",
"main": "lib/index.js",
"scripts": {
Expand Down
31 changes: 0 additions & 31 deletions test/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,37 +139,6 @@ describe('Actor', function () {
await retry(async () => (await query(listener, {}, 30)).should.deep.equal([1, 2, 3]), 5, 10);
});

it('evalutes out of order when returning a promise from a stateless actor function', async function () {
let child = spawnStateless(
system,
async function (msg) {
if (msg.number === 2) {
await delay(30);
}
dispatch(msg.listener, { number: msg.number });
},
'testActor'
);

let listener = spawn(
system,
async function (state = [], msg) {
if (msg.number) {
return [...state, msg.number];
} else {
dispatch(this.sender, state);
}
return state;
},
'listener'
);

dispatch(child, { listener, number: 1 });
dispatch(child, { listener, number: 2 });
dispatch(child, { listener, number: 3 });
await retry(async () => (await query(listener, {}, 30)).should.deep.equal([1, 3, 2]), 5, 10);
});

it('should not automatically stop if error is thrown and actor is stateless', async function () {
console.error = ignore;
let child = spawnStateless(system, (msg) => { throw new Error('testError'); });
Expand Down

0 comments on commit 74f5a20

Please sign in to comment.