Skip to content

Commit

Permalink
Added name to actor
Browse files Browse the repository at this point in the history
  • Loading branch information
ncthbrt committed May 11, 2018
1 parent badfe12 commit bd7d065
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/Hello_World_Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createAdapterIfNotExists(parent, adapterOpt) {
if (adapterOpt) {
return adapterOpt[0];
} else {
return Nact.spawnAdapter(parent, (function (param) {
return Nact.spawnAdapter(/* None */0, parent, (function (param) {
return /* Hello */[param[0]];
}));
}
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": "reason-nact",
"version": "3.2.2",
"version": "3.3.0",
"description": "let reason-nact = (node.js, reason, actors) ⇒ your µ services have never been so typed",
"repository": "https://github.com/ncthbrt/reason-nact",
"author": "Nick Cuthbert (https://github.com/ncthbrt)",
Expand Down
16 changes: 11 additions & 5 deletions src/Nact.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,16 @@ function nobody() {
return /* ActorRef */[new References.Nobody()];
}

function spawnAdapter(parent, mapping) {
return spawnStateless(/* None */0, /* None */0, /* None */0, parent, (function (msg, _) {
return Promise.resolve(dispatch$1(parent, Curry._1(mapping, msg)));
}));
function spawnAdapter(name, parent, mapping) {
if (name) {
return spawnStateless(/* Some */[name[0]], /* None */0, /* None */0, parent, (function (msg, _) {
return Promise.resolve(dispatch$1(parent, Curry._1(mapping, msg)));
}));
} else {
return spawnStateless(/* None */0, /* None */0, /* None */0, parent, (function (msg, _) {
return Promise.resolve(dispatch$1(parent, Curry._1(mapping, msg)));
}));
}
}

function start(name, persistenceEngine, logger, _) {
Expand All @@ -425,7 +431,7 @@ function start(name, persistenceEngine, logger, _) {
var loggingActorFunction = logger$1;
var system = param;
var loggerActor = Curry._1(loggingActorFunction, /* ActorRef */[system]);
return spawnAdapter(loggerActor, fromJsLog)[0];
return spawnAdapter(/* None */0, loggerActor, fromJsLog)[0];
})),
plugins
];
Expand Down
15 changes: 11 additions & 4 deletions src/Nact.re
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,17 @@ let dispatch = (ActorRef(recipient), msg) =>

let nobody = () => ActorRef(Nact_bindings.nobody());

let spawnAdapter = (parent, mapping) =>
spawnStateless(parent, (msg, _) =>
resolve(dispatch(parent, mapping(msg)))
);
let spawnAdapter = (~name=?, parent, mapping) =>
switch (name) {
| Some(name) =>
spawnStateless(~name, parent, (msg, _) =>
resolve(dispatch(parent, mapping(msg)))
)
| None =>
spawnStateless(parent, (msg, _) =>
resolve(dispatch(parent, mapping(msg)))
)
};

let mapLoggingActor = (loggingActorFunction: Log.logger, system) => {
let loggerActor = loggingActorFunction(ActorRef(system));
Expand Down
3 changes: 2 additions & 1 deletion src/Nact.rei
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ let spawnPersistent:
actorRef('msg);

let spawnAdapter:
(actorRef('parentMsg), 'msg => 'parentMsg) => actorRef('msg);
(~name: string=?, actorRef('parentMsg), 'msg => 'parentMsg) =>
actorRef('msg);

let start:
(
Expand Down

0 comments on commit bd7d065

Please sign in to comment.