{"id":16874515,"url":"https://github.com/joway/node-routine","last_synced_at":"2025-03-22T07:31:40.611Z","repository":{"id":35079854,"uuid":"204477411","full_name":"joway/node-routine","owner":"joway","description":"A library to implement Goroutine-Like API with worker_threads.","archived":false,"fork":false,"pushed_at":"2022-03-25T05:59:30.000Z","size":1275,"stargazers_count":43,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-14T15:32:58.221Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://routine.joway.io","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/joway.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":"2019-08-26T13:05:04.000Z","updated_at":"2024-08-27T21:53:31.000Z","dependencies_parsed_at":"2022-08-08T04:16:30.629Z","dependency_job_id":null,"html_url":"https://github.com/joway/node-routine","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/joway%2Fnode-routine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joway%2Fnode-routine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joway%2Fnode-routine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joway%2Fnode-routine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joway","download_url":"https://codeload.github.com/joway/node-routine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221824441,"owners_count":16886807,"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-13T15:33:05.593Z","updated_at":"2024-10-28T12:14:36.223Z","avatar_url":"https://github.com/joway.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-routine\n\n\u003cimg width=\"200px;\" src=\"public/logo.png\" /\u003e\n\n[![npm](https://img.shields.io/npm/v/node-routine.svg)](https://www.npmjs.com/package/node-routine)\n[![npm](https://img.shields.io/npm/dt/node-routine.svg)](https://www.npmjs.com/package/node-routine)\n\nnode-routine is a library to implement [Goroutine-Like API](https://gobyexample.com/goroutines) with [worker_threads](https://nodejs.org/api/worker_threads.html).\n\nCompared to using the worker threads low level API directly, node-routine can make your codes more elegantly, like:\n\n```\nawait go(() =\u003e (Math.random()))\n```\n\n## Documentation\n\n[Documentation](https://routine.joway.io)\n\n## Architecture\n\n![](public/architecture.png)\n\n## Requirement\n\n- Nodejs \u003e= 11.7\n- Nodejs \u003e= 10.5 with `--experimental-worker` flag\n\n## Install\n\n```shell\nnpm install -S node-routine\n```\n\n## Quick Example\n\n```javascript\nconst { go, init, shutdown } = require('node-routine')\n\n// init a worker threads pool\ninit({\n  maxWorkerThreads: 2,\n})\n\nasync function calc() {\n  // every routine will be executed in worker threads pool\n  const count = 10000\n  const num = await go(() =\u003e {\n    let total = 0\n    for (let i = 0; i \u003c count; ++i) {\n      total += i\n    }\n    return total\n  }, { count })\n\n  return num\n}\n\ncalc().then((total) =\u003e {\n  console.log('Got', total)\n  shutdown()\n})\n```\n\n## Benchmark\n\n- [node-routine](https://github.com/joway/node-routine)\n- [microjob](https://github.com/wilk/microjob)\n\n[Benchmark Code](bench/job.ts)\n\nEnv: Macbook Pro, 13-inch, 2018, 2.3 GHz Intel Core i5\n\nCommend: `npm run bench`\n\n```\n  ✓ CPU intensive task using microjob (14ms)\n  ✓ CPU intensive task using node-routine (4ms)\n  ✓ IO intensive task using microjob (20163ms)\n  ✓ IO intensive task using node-routine (5224ms)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoway%2Fnode-routine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoway%2Fnode-routine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoway%2Fnode-routine/lists"}