Actor model (style) API in JS
npm install aktor-js> Exploring the potential benefits of implementing APIs in the style of the Actor Model,
even in single-threaded programming environments such as Javascript.
- [x] createSystem()
- [x] system.actorOf(IActorFactory) -> ActorRef
- [x] actor.tell() - fire & forget message
- [x] actor.ask() - ask & await async response from an actor
- [x] actor.stop() - send a message instructing an actor to terminate
context.stop(IActorRef) - allow an actor to be stopped via a refcontext.gracefulStop(IActorRef) - allow an actor to be stopped via a ref with confirmation (for sequencing etc)context.actorOf(IActorFactory) - allow an actor to create more actorscontext.parent - allow an actor to access it's parent (in order to send it messages)context.self - allow an actor to access it's own ref (in order to send it's self messages)context.become(newHandler) - designate a new handler for future messages http://doc.akka.io/docs/akka/current/scala/actors.html#Graceful_Stopcontext.actorSelection(lookup: string) - allow actor lookups via paths, such as /system /deadletter etcreceive(payload, message, sender)sender.reply() for replying directly to a messagemappedMethods define 1 function per message namesender - allow every message access to an ActorRef that allow communication with the sender ``js`
receive (payload message sender)
switch payload
case 'ping' sender.reply 'pong'
default sender.reply 'missing'
// callsite
actor.ask 'ping'
|> resp console.log 'resp:' + resp
$3
- actorOf(...)Stop
- [x] path is reserved
- [ ] uuid is assigned
- [x] actor instance is created
- [x] preStart is called on instance
- Incarnation (restarting)
- [x] preRestart called on old instance
- [x] new instance replaces old
- [x] postRestart called on new instance
- , context.stop() or PoisonPillTerminated
- [x] postStop is called on instance
- [x] actor is removed from the internal system register
- [ ] is sent to watchersbecome()
- [x] path is free to be used again
- graceful stop http://doc.akka.io/docs/akka/current/scala/actors.html#Graceful_Stop
- [ ] - designate a new handler for future messages
$3
- [x] actorOf() only ever creates a new actor, and it creates it as a direct child of the context /deadletters
on which this method is invoked (which may be any actor or actor system).
- [ ] all messages sent to stopped or non-existing actors are re-routed here /system` is the guardian actor for all system-created top-level actors, e.g. logging
- [x]
listeners or actors automatically deployed by configuration at the start of the actor system.