{"id":15362035,"url":"https://github.com/tj/node-actorify","last_synced_at":"2025-06-26T01:02:39.133Z","repository":{"id":11474826,"uuid":"13943427","full_name":"tj/node-actorify","owner":"tj","description":"Turn any node.js duplex stream into an actor","archived":false,"fork":false,"pushed_at":"2019-01-03T11:22:37.000Z","size":19,"stargazers_count":109,"open_issues_count":3,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-26T01:02:38.858Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/tj.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":"2013-10-29T01:22:59.000Z","updated_at":"2025-06-10T18:14:01.000Z","dependencies_parsed_at":"2022-09-14T03:21:21.271Z","dependency_job_id":null,"html_url":"https://github.com/tj/node-actorify","commit_stats":null,"previous_names":["visionmedia/node-actorify"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tj/node-actorify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-actorify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-actorify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-actorify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-actorify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tj","download_url":"https://codeload.github.com/tj/node-actorify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-actorify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261978905,"owners_count":23239417,"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-10-01T12:58:13.861Z","updated_at":"2025-06-26T01:02:39.072Z","avatar_url":"https://github.com/tj.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# actorify\n\n  Turn any duplex stream into an actor. Built on the the [AMP](https://github.com/visionmedia/node-amp) protocol\n  for opaque binary and javascript argument support.\n\n  Actors are similar to traditional RPC however they are isolated units of communication, an actor receives and sends zero or more messages to and from \n  its peer with bi-directional messaging. Typical RPC is done at the process-level,\n  meaning in order to work with data coupled with an identifier such as a user id \n  that the id must be passed each request, whereas an actor may retain this state.\n\n## Features\n\n - fast\n - clean api\n - json support\n - request timeouts\n - opaque binary support\n - simple flexible protocol\n - bi-directional messaging\n - request/response support\n\n## Installation\n\n```\n$ npm install actorify\n```\n\n## Guide\n\n### Example\n\n  Simple hello world PING/PONG example:\n\n```js\nvar net = require('net');\nvar actorify = require('actorify');\n\n// server\n\nnet.createServer(function(sock){\n  var actor = actorify(sock);\n\n  actor.on('ping', function(){\n    console.log('PING');\n    actor.send('pong');\n  });\n}).listen(3000);\n\n// client\n\nvar sock = net.connect(3000);\nvar actor = actorify(sock);\n\nsetInterval(function(){\n  actor.send('ping');\n  actor.once('pong', function(){\n    console.log('PONG');\n  });\n}, 300);\n```\n\n  Sending a single request with multiple async responses,\n  also illustrates how arguments may be primitives, json objects,\n  or opaque binary such as sending an image over the wire for\n  resizing, receiving multiple thumbnail blobs and their \n  respective size:\n\n```js\nvar net = require('net');\nvar actorify = require('actorify');\n\n// client\n\nnet.createServer(function(sock){\n  var actor = actorify(sock);\n\n  var img = Buffer.from('faux data');\n\n  actor.on('image thumbnails', function(img, sizes){\n    console.log('%s byte image -\u003e %s', img.length, sizes.join(', '));\n    sizes.forEach(function(size){\n      actor.send('thumb', size, Buffer.from('thumb data'));\n    });\n  });\n}).listen(3000);\n\n// client\n\nsetInterval(function(){\n  var sock = net.connect(3000);\n  var actor = actorify(sock);\n\n  console.log('send image for thumbs');\n  var img = Buffer.from('faux image');\n  actor.send('image thumbnails', img, ['150x150', '300x300']);\n\n  actor.on('thumb', function(size, img){\n    console.log('thumb: %s', size);\n  });\n}, 500);\n```\n\n  You may also associate callbacks with an actor message, effectively\n  turning it into a traditional RPC call:\n\n```js\nactor.send('get user', 'tobi', function(err, user){\n  \n});\n\nactor.on('get user', function(name, reply){\n  getUser(name, function(err, user){\n    reply(err, user);\n  });\n});\n```\n\n### Timeouts\n\n  When performing a request you may optionally timeout the response,\n  after which an `Error` will be passed to the callback and any subsequent\n  response will be ignored.\n\n  The argument may be numeric milliseconds or represented as a string such\n  as \"5s\", \"10m\", \"1 minute\", \"30 seconds\", etc. By default there is __no__\n  timeout.\n\n```js\nactor.send('hello', function(err, res){\n  \n}).timeout('5s');\n```\n\n### Error Handling\n\n  Stream errors are _not_ handled, you must add an \"error\" listener\n  to the `stream` passed to actorify().\n\n## Benchmarks\n\n  Benchmarks on my first generation MBP Retina with node 0.11.x.\n  Real results are likely higher since having the \n  producer on the same machine as the consumer makes\n  results misleading.\n\n  With __64b__ messages:\n\n```\n      min: 56,818 ops/s\n     mean: 159,207 ops/s\n   median: 138,888 ops/s\n    total: 1,376,188 ops in 8.644s\n  through: 1.52 mb/s\n```\n\n  With __1kb__ messages:\n\n```\n      min: 56,179 ops/s\n     mean: 153,919 ops/s\n   median: 142,857 ops/s\n    total: 909,974 ops in 5.912s\n  through: 150.31 mb/s\n```\n\n  With __10kb__ messages:\n\n```\n      min: 11,389 ops/s\n     mean: 64,167 ops/s\n   median: 64,102 ops/s\n    total: 352,025 ops in 5.486s\n  through: 626.64 mb/s\n```\n\n With __32kb__ messages:\n\n```\n      min: 7,032 ops/s\n     mean: 14,269 ops/s\n   median: 23,584 ops/s\n    total: 86,329 ops in 6.05s\n  through: 445.91 mb/s\n```\n\n\n# License\n\n  MIT\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fnode-actorify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftj%2Fnode-actorify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fnode-actorify/lists"}