{"id":13567077,"url":"https://github.com/shakyShane/actor-js","last_synced_at":"2025-04-04T01:31:02.279Z","repository":{"id":57175363,"uuid":"88405866","full_name":"shakyShane/actor-js","owner":"shakyShane","description":"Exploring the potential benefits of implementing APIs in the style of the Actor Model, even in single-threaded programming environments such as Javascript.","archived":false,"fork":false,"pushed_at":"2018-05-15T17:34:41.000Z","size":329,"stargazers_count":33,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T05:11:13.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shakyShane.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-16T10:21:27.000Z","updated_at":"2025-01-03T04:16:34.000Z","dependencies_parsed_at":"2022-09-03T08:51:57.512Z","dependency_job_id":null,"html_url":"https://github.com/shakyShane/actor-js","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Factor-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Factor-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Factor-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Factor-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shakyShane","download_url":"https://codeload.github.com/shakyShane/actor-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247107816,"owners_count":20884793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:02:23.093Z","updated_at":"2025-04-04T01:31:01.813Z","avatar_url":"https://github.com/shakyShane.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Actor Model in JS\n\n\u003e Exploring the potential benefits of implementing APIs in the *style* of the Actor Model, \neven in single-threaded programming environments such as Javascript.\n\n## TODO\n\n### Actor system `ActorSystem`\n\n- [x] `createSystem()`\n- [x] `system.actorOf(IActorFactory) -\u003e ActorRef` \n\n### Actors `Actor`\n\n- [x] `actor.tell()` - fire \u0026 forget message\n- [x] `actor.ask()` - ask \u0026 await async response from an actor\n- [x] `actor.stop()` - send a message instructing an actor to terminate\n\n### Actor context `ActorContext`\n- [x] `context.stop(IActorRef)` - allow an actor to be stopped via a ref\n- [x] `context.gracefulStop(IActorRef)` - allow an actor to be stopped via a ref with confirmation (for sequencing etc)\n- [x] `context.actorOf(IActorFactory)` - allow an actor to create more actors\n- [x] `context.parent` - allow an actor to access it's parent (in order to send it messages)\n- [x] `context.self` - allow an actor to access it's own ref (in order to send it's self messages)\n- [ ] `context.become(newHandler)` - designate a new handler for future messages [http://doc.akka.io/docs/akka/current/scala/actors.html#Graceful_Stop](http://doc.akka.io/docs/akka/current/scala/actors.html#Graceful_Stop)\n- [x] `context.actorSelection(lookup: string)` - allow actor lookups via paths, such as `/system` `/deadletter` etc\n\n### Actor receive method\n- [x] `receive(payload, message, sender)`\n- [x] `sender.reply()` for replying directly to a message\n- [x] `mappedMethods` define 1 function per message name\n- [x] handle cancellation of pending message should a new one override it\n- [x] pass state into mapped methods for encapsulated state management\n- [x] `sender` - allow every message access to an ActorRef that allow communication with the sender\n\n    ```js\n    receive (payload message sender)\n      switch payload\n        case 'ping' sender.reply 'pong'\n        default sender.reply 'missing'\n      \n    // callsite\n    actor.ask 'ping'\n      |\u003e resp console.log 'resp:' + resp\n    ```\n    \n### Actor Lifecycle\n\n- `actorOf(...)`\n    - [x] path is reserved\n    - [ ] uuid is assigned\n    - [x] actor instance is created\n    - [x] preStart is called on instance\n    \n- Incarnation (restarting)\n    - [x] preRestart called on old instance\n    - [x] new instance replaces old\n    - [x] postRestart called on new instance\n    \n- `Stop`, `context.stop()` or `PoisonPill`\n    - [x] postStop is called on instance\n    - [x] actor is removed from the internal system register\n    - [ ] `Terminated` is sent to watchers\n    - [x] path is free to be used again\n    \n- graceful stop [http://doc.akka.io/docs/akka/current/scala/actors.html#Graceful_Stop](http://doc.akka.io/docs/akka/current/scala/actors.html#Graceful_Stop)\n    - [ ] `become()` - designate a new handler for future messages\n    \n### Actor References, Paths and Addresses\n\n- [x] `actorOf()` only ever creates a new actor, and it creates it as a direct child of the context \n    on which this method is invoked (which may be any actor or actor system).\n- [ ] `/deadletters` all messages sent to stopped or non-existing actors are re-routed here \n- [x] `/system` is the guardian actor for all system-created top-level actors, e.g. logging \n    listeners or actors automatically deployed by configuration at the start of the actor system.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FshakyShane%2Factor-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FshakyShane%2Factor-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FshakyShane%2Factor-js/lists"}