{"id":16641594,"url":"https://github.com/scrwdrv/worker-communication","last_synced_at":"2026-05-15T01:05:46.364Z","repository":{"id":57399219,"uuid":"230044552","full_name":"scrwdrv/worker-communication","owner":"scrwdrv","description":"This module provide bilateral communication with callback between cluster worker and master, node.js child process is supported too.","archived":false,"fork":false,"pushed_at":"2020-01-22T03:11:50.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T15:27:32.368Z","etag":null,"topics":["callback","child-process","cluster","ipc","nodejs","typescript","worker"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scrwdrv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-25T05:04:15.000Z","updated_at":"2021-07-03T10:36:32.000Z","dependencies_parsed_at":"2022-09-01T07:00:19.668Z","dependency_job_id":null,"html_url":"https://github.com/scrwdrv/worker-communication","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrwdrv%2Fworker-communication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrwdrv%2Fworker-communication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrwdrv%2Fworker-communication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrwdrv%2Fworker-communication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scrwdrv","download_url":"https://codeload.github.com/scrwdrv/worker-communication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243159166,"owners_count":20245675,"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":["callback","child-process","cluster","ipc","nodejs","typescript","worker"],"created_at":"2024-10-12T07:47:10.955Z","updated_at":"2025-10-29T01:14:23.852Z","avatar_url":"https://github.com/scrwdrv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# worker-communication\n This module provide bilateral communication with callback between cluster worker and master, node.js child process is supported too.\n\n\n## Installation\n```sh\nnpm i worker-communication\n```\n\n## Usage\n\n### Master\n```js\nimport CPC from 'worker-communication';\nimport * as cluster from 'cluster';\n// or       childProcess from 'child_process'\n\nconst cpc = new CPC();\n\nconst worker = cpc.tunnel(cluster.fork())\n// or          cpc.tunnel(childProcess.fork('./worker.js'));\n\ncpc.onWorker('requestJob', (req, res) =\u003e {\n    res({\n        reqHeader: req,\n        timestamp: Date.now()\n    }, null);\n});\n\nworker.sendJob('idle', 'just relax...');\n```\n\n### Worker (cluster worker or ```child_process.fork()```)\n```js\nimport CPC from 'worker-communication';\n\nconst cpc = new CPC(); \n\ncpc.onMaster('idle', (req) =\u003e {\n    console.log(req);\n    // output: just relax...\n});\n\nlet reqHeader = [123, 456];\n\ncpc.sendJob('requestJob', reqHeader, (jobHeader, job) =\u003e {\n    console.log(jobHeader);\n    // output: { reqHeader: [123, 456], timestamp: 1577252484830 }\n    console.log(job);\n    // output: null\n});\n```\n\n## Note\n\n Master \u0026 worker is relative, a worker can also be a master to the process it forks.\n So in this scenario, ```onMater()``` and ```onWorker()``` can be used at the same time to communicate its master and worker.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrwdrv%2Fworker-communication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscrwdrv%2Fworker-communication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrwdrv%2Fworker-communication/lists"}