Skip to content

Commit

Permalink
Updated query to accept message functions allowing more sophisticated…
Browse files Browse the repository at this point in the history
… message behaviour
  • Loading branch information
ncthbrt committed Dec 5, 2017
1 parent b41b6e5 commit c52ce89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class Actor {
deffered.promise.then(() => clearTimeout(timeoutHandle)).catch(() => { });

let tempReference = new TemporaryReference(deffered);
if (typeof (message) === 'function') {
message = message(tempReference);
}
this.dispatch(message, tempReference);
return deffered.promise;
}
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": "4.0.1",
"version": "4.1.0",
"description": "nact ⇒ node.js + actors = your services have never been so µ",
"main": "lib/index.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions test/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ describe('Actor', function () {
);
(await query(actor, 'test', 50)).should.equal('done');
});

it(`should accept a message function which takes in the temporary actor reference`, async function () {
let actor = spawnStateless(
system,
async (msg, ctx) => { dispatch(msg, 'done', ctx.self); },
'test'
);
(await query(actor, (sender) => sender, 50)).should.equal('done');
});
});

describe('#state$', function () {
Expand Down

0 comments on commit c52ce89

Please sign in to comment.