From bd7d0653fe9d419753e59c7f88b6ba3f4f70a63a Mon Sep 17 00:00:00 2001 From: Nick Cuthbert Date: Fri, 11 May 2018 11:26:40 +0200 Subject: [PATCH] Added name to actor --- examples/Hello_World_Adapter.js | 2 +- package.json | 2 +- src/Nact.js | 16 +++++++++++----- src/Nact.re | 15 +++++++++++---- src/Nact.rei | 3 ++- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/examples/Hello_World_Adapter.js b/examples/Hello_World_Adapter.js index ca74297..4e1d99e 100644 --- a/examples/Hello_World_Adapter.js +++ b/examples/Hello_World_Adapter.js @@ -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]]; })); } diff --git a/package.json b/package.json index 299b1b9..1596984 100644 --- a/package.json +++ b/package.json @@ -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)", diff --git a/src/Nact.js b/src/Nact.js index 9489409..6a1c4aa 100644 --- a/src/Nact.js +++ b/src/Nact.js @@ -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, _) { @@ -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 ]; diff --git a/src/Nact.re b/src/Nact.re index 4adf7cb..2d5c48c 100644 --- a/src/Nact.re +++ b/src/Nact.re @@ -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)); diff --git a/src/Nact.rei b/src/Nact.rei index 0760a0f..ef6fa6f 100644 --- a/src/Nact.rei +++ b/src/Nact.rei @@ -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: (