{"id":16513422,"url":"https://github.com/dimaamega/asynchronous-concurrency-primitives-js","last_synced_at":"2026-04-14T07:32:21.778Z","repository":{"id":62245455,"uuid":"397750018","full_name":"DimaAmega/asynchronous-concurrency-primitives-js","owner":"DimaAmega","description":"Implementation of asynchronous Barrier, Mutex, RWMutex in javascript","archived":false,"fork":false,"pushed_at":"2023-07-28T08:13:43.000Z","size":74,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-02T10:23:32.049Z","etag":null,"topics":["asyncronous","coroutines","javascript","nodejs","promise"],"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/DimaAmega.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,"governance":null}},"created_at":"2021-08-18T22:27:42.000Z","updated_at":"2023-07-18T03:10:37.000Z","dependencies_parsed_at":"2023-07-28T09:39:02.282Z","dependency_job_id":null,"html_url":"https://github.com/DimaAmega/asynchronous-concurrency-primitives-js","commit_stats":null,"previous_names":["dimaamega/asynchronous-concurrency-primitives-js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DimaAmega/asynchronous-concurrency-primitives-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimaAmega%2Fasynchronous-concurrency-primitives-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimaAmega%2Fasynchronous-concurrency-primitives-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimaAmega%2Fasynchronous-concurrency-primitives-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimaAmega%2Fasynchronous-concurrency-primitives-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DimaAmega","download_url":"https://codeload.github.com/DimaAmega/asynchronous-concurrency-primitives-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DimaAmega%2Fasynchronous-concurrency-primitives-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31786785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["asyncronous","coroutines","javascript","nodejs","promise"],"created_at":"2024-10-11T16:08:55.888Z","updated_at":"2026-04-14T07:32:21.754Z","avatar_url":"https://github.com/DimaAmega.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# asynchronous concurrency primitives js\n[![Node.js CI](https://github.com/DimaAmega/asynchronous-mutex-js/actions/workflows/tests.js.yml/badge.svg)](https://github.com/DimaAmega/asynchronous-mutex-js/actions/workflows/tests.js.yml)\n\n[![Open in Codeflow](https://developer.stackblitz.com/img/open_in_codeflow.svg)](https:///pr.new/DimaAmega/asynchronous-concurrency-primitives-js\n)\n\nThere are a few asynchronous concurrency primitives js:\n\n- [barrier.js](./examples/simple-barrier.js) \n- [mutex.js](./examples/simple-mutex.js)\n- [rwmutex.js](./tests/rwmutex.test.js#L71)\n\n\nAlso see [tests](./tests)\n\n### Get started:\ndeps:\n```shell\nnpm i\n```\n\nrun tests:\n```shell\nnpm test\n```\n\n### Barrier\n```js\nconst Coroutines = [0, 1, 2, 3].map((n) =\u003e `coroutine ${n}`)\n\n// Global variables\nconst b = new Barrier()\nconst c = new ColorLog()\n\n;(async () =\u003e {\n  c.log(`Lock barrier`, Coroutines[0])\n  await b.Lock()\n  c.log(`Done`, Coroutines[0])\n})()\n\n;(async () =\u003e {\n  c.log(`Sleep 1s ...`, Coroutines[1])\n  await sleep(1)\n  b.UnLock()\n  c.log(`barrier UnLock was invoked :)`, Coroutines[1])\n})()\n```\n\n\u003cimg width=\"763\" alt=\"image\" src=\"https://user-images.githubusercontent.com/32310771/229280109-cb6c15a9-4267-42b4-8bc6-b8e8710dc2cc.png\"\u003e\n\n\n\n### Mutex\n```js\n// setup\nconst CoroutineS_NUMBER = 3\nconst Coroutines = [...Array(CoroutineS_NUMBER).keys()].map(\n  (n) =\u003e `coroutine ${n}`\n)\nconst sleepTimes = [...Array(CoroutineS_NUMBER).keys()]\n\n// Global variables\nconst m = new Mutex()\nconst c = new ColorLog()\n\nconst CreateWorker = (sleepTime, workerNumber) =\u003e async () =\u003e {\n  c.log(`Lock mutex`, Coroutines[workerNumber])\n  await m.Lock()\n  c.log(`In CS`, Coroutines[workerNumber])\n  c.log(`Sleep ${sleepTime}s ...`, Coroutines[workerNumber])\n  await sleep(sleepTime)\n  c.log(`Out CS`, Coroutines[workerNumber])\n  m.UnLock()\n  c.log(`mutex UnLock was invoked :)`, Coroutines[workerNumber])\n  c.log(`Done`, Coroutines[workerNumber])\n}\n\n;(async () =\u003e {\n  const promises = sleepTimes\n    // create workers\n    .map((sleepTime, workerNumber) =\u003e CreateWorker(sleepTime, workerNumber))\n    // execute workers\n    .map((worker) =\u003e worker())\n  // wait all tasks\n  await Promise.all(promises)\n})()\n```\n\n\u003cimg width=\"763\" alt=\"image\" src=\"https://user-images.githubusercontent.com/32310771/229280139-6e301420-da92-4e8f-a12f-f41d6515bc00.png\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimaamega%2Fasynchronous-concurrency-primitives-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimaamega%2Fasynchronous-concurrency-primitives-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimaamega%2Fasynchronous-concurrency-primitives-js/lists"}